jwt in headers+localstorage instead of httpOnly cookie (#117)

This commit is contained in:
Marco
2023-12-27 14:32:08 +01:00
committed by GitHub
parent f7ba203ed0
commit c5535fad71
14 changed files with 125 additions and 155 deletions

View File

@@ -7,7 +7,7 @@ export const ffetch = <T>(url: string, opt?: RequestInit) => tryCatch(
const fetcher = async <T>(url: string, opt?: RequestInit) => {
const res = await fetch(url, opt)
const jwt = localStorage.getItem('token')
if (opt && !opt.headers) {
opt.headers = {
@@ -15,6 +15,12 @@ const fetcher = async <T>(url: string, opt?: RequestInit) => {
}
}
if (opt?.headers) {
opt.headers = { ...opt.headers, 'X-Authentication': jwt ?? '' }
}
const res = await fetch(url, opt)
if (!res.ok) {
throw await res.text()
}