first commit
This commit is contained in:
16
src/shared/api/csrf.ts
Normal file
16
src/shared/api/csrf.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { API_URL } from '@shared/config/env'
|
||||
|
||||
interface CsrfResponse {
|
||||
header_name: string
|
||||
token: string
|
||||
}
|
||||
|
||||
let cachedToken: string | null = null
|
||||
|
||||
export async function getCsrfToken(): Promise<string> {
|
||||
if (cachedToken) return cachedToken
|
||||
const res = await fetch(`${API_URL}/csrf/token`)
|
||||
const data: CsrfResponse = await res.json()
|
||||
cachedToken = data.token
|
||||
return cachedToken
|
||||
}
|
||||
Reference in New Issue
Block a user