fix: authorization / registration
This commit is contained in:
@@ -9,7 +9,13 @@ export const tokenStore = {
|
|||||||
const REFRESH_URL = 'https://app.auth.elcsa.ru/v1/jwt/refresh'
|
const REFRESH_URL = 'https://app.auth.elcsa.ru/v1/jwt/refresh'
|
||||||
|
|
||||||
export async function refreshAccessToken(): Promise<string> {
|
export async function refreshAccessToken(): Promise<string> {
|
||||||
const res = await fetch(REFRESH_URL, { method: 'POST', credentials: 'include' })
|
const { getCsrfToken } = await import('./csrf')
|
||||||
|
const csrf = await getCsrfToken()
|
||||||
|
const res = await fetch(REFRESH_URL, {
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'include',
|
||||||
|
headers: { 'X-CSRF-Token': csrf },
|
||||||
|
})
|
||||||
if (!res.ok) throw new Error('Unauthorized')
|
if (!res.ok) throw new Error('Unauthorized')
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
tokenStore.set(data.access_token)
|
tokenStore.set(data.access_token)
|
||||||
|
|||||||
Reference in New Issue
Block a user