-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(csrf): simplify
token handling
- Loading branch information
1 parent
d87a3b2
commit 97bea08
Showing
4 changed files
with
22 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
"a11y", | ||
"checkout", | ||
"ci", | ||
"csrf", | ||
"customFetch", | ||
"dialog", | ||
"eslint", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,24 @@ | ||
import { defineStore } from 'pinia' | ||
import { getCSRFHeader } from '~/utils/fetch' | ||
|
||
/** | ||
The csrf header is added to non GET requests to prevent Cross-site request forgery | ||
We get the csrf header from GET requests put them in this store and apply them to non GET requests. | ||
**/ | ||
|
||
const csrfStore = defineStore('csrf_store', () => { | ||
const header = ref<[string, string] | null | undefined>() | ||
return { header } | ||
const tokenCsrf = ref<string >('') | ||
return { tokenCsrf } | ||
}) | ||
|
||
export function useCsrfStore() { | ||
const { header } = storeToRefs(csrfStore()) | ||
const { tokenCsrf } = storeToRefs(csrfStore()) | ||
|
||
const csrfHeader = computed(() => header.value) | ||
|
||
function setCsrfHeader(headers: Headers) { | ||
const h = getCSRFHeader(headers) | ||
if (h) { | ||
header.value = h | ||
} | ||
function setTokenCsrf(token: string) { | ||
tokenCsrf.value = token | ||
} | ||
|
||
return { | ||
csrfHeader, | ||
setCsrfHeader, | ||
setTokenCsrf, | ||
tokenCsrf, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.