feat: added initial implementation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createContext, useCallback, useContext, useEffect, useState } from "react";
|
||||
import { apiGet, apiPost } from "../api/client";
|
||||
import { apiGet, apiPost, ApiError } from "../api/client";
|
||||
|
||||
const STORAGE_ACCESS = "auth_access";
|
||||
const STORAGE_REFRESH = "auth_refresh";
|
||||
@@ -50,7 +50,12 @@ export function AuthProvider({ children }) {
|
||||
setUser(data);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((err) => {
|
||||
const status = err instanceof ApiError ? err.status : err?.status;
|
||||
if (status !== 401) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
// Token invalid, try refresh
|
||||
if (!refreshToken) {
|
||||
logout();
|
||||
|
||||
Reference in New Issue
Block a user