Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLA-1864] Remove csrf cookie meta and use cookie instead #127

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading