jwt in headers+localstorage instead of httpOnly cookie (#117)
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user