Skip to content

Commit

Permalink
[PLA-1864] Remove csrf cookie meta and use cookie instead (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner authored Jun 26, 2024
1 parent ffa0c52 commit e4226d3
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 12 deletions.
7 changes: 1 addition & 6 deletions resources/js/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ export class ApiService {
}): Promise<any> {
let body: string | null = null;
const fullUrl = url;
const csrf = document.head.querySelector('meta[name="csrf-token"]')?.getAttribute('content');

if (Object.keys(data).length > 0) {
body = JSON.stringify(data);
}

if (!useAppStore().isMultiTenant) {
headers.Authorization = useAppStore().config.authorization_token;
} else {
headers['X-CSRF-TOKEN'] = csrf;
}

const resp = await fetch(fullUrl, {
Expand All @@ -63,9 +60,7 @@ export class ApiService {
});

if (resp.status === 419 && nest && useAppStore().isMultiTenant) {
if (await this.reloadCsrf()) {
return this.request({ url, method, data, headers });
}
return this.request({ url, method, data, headers });
}

if (resp.status === 204) {
Expand Down
2 changes: 0 additions & 2 deletions resources/js/components/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ import CollapseCard from '../CollapseCard.vue';
import Tooltip from '../Tooltip.vue';
import { AuthApi } from '~/api/auth';
import ConfirmModal from '../ConfirmModal.vue';
import { ApiService } from '~/api';
import SettingsChangeEmail from './SettingsChangeEmail.vue';
import VerifyPasswordModal from './VerifyPasswordModal.vue';
Expand Down Expand Up @@ -137,7 +136,6 @@ const formatName = (name: string) => {
const deleteAccount = async (password) => {
await AuthApi.deleteAccount(password);
appStore.clearLogin();
await ApiService.reloadCsrf();
};
watch(
Expand Down
2 changes: 0 additions & 2 deletions resources/js/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ export const useAppStore = defineStore('app', {
throw [{ field: 'Login error', message: 'Invalid credentials' }];
}

await ApiService.reloadCsrf();
if (this.config.tenant) {
await this.getUser();
if (!this.user.isVerified) {
Expand All @@ -233,7 +232,6 @@ export const useAppStore = defineStore('app', {
this.loggedIn = false;
await AuthApi.logout();
this.clearLogin();
await ApiService.reloadCsrf();
},
clearLogin() {
this.user = null;
Expand Down
3 changes: 1 addition & 2 deletions resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>Enjin Platform</title>
<title>Enjin Platform</title>
<link href="/vendor/platform-ui/favicon.png" rel="shortcut icon" type="image/x-icon" />

@vite('resources/css/app.css', 'vendor/platform-ui/build')
Expand Down

0 comments on commit e4226d3

Please sign in to comment.