Raid groups page working
This commit is contained in:
@@ -14,13 +14,15 @@ type AuthProviderState = {
|
||||
setJwt: (token: string | null) => void;
|
||||
expiration: Date | null;
|
||||
setExpiration: (expiration: Date | null) => void;
|
||||
accountId: string | null;
|
||||
}
|
||||
|
||||
const initialState: AuthProviderState = {
|
||||
jwt: null,
|
||||
setJwt: () => null,
|
||||
expiration: null,
|
||||
setExpiration: () => null
|
||||
setExpiration: () => null,
|
||||
accountId: null
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthProviderState>(initialState);
|
||||
@@ -32,6 +34,7 @@ export function AuthProvider({
|
||||
const [ jwt, setJwt ] = useState<string | null>(null);
|
||||
const [ expiration, setExpiration ] = useState<Date | null>(null);
|
||||
const [ firstFetch, setFirstFetch ] = useState(true);
|
||||
const [ accountId, setAccountId ] = useState<string | null>(null);
|
||||
|
||||
|
||||
const fetchToken = useCallback(async () => {
|
||||
@@ -41,8 +44,12 @@ export function AuthProvider({
|
||||
//If the token is retrieved
|
||||
if((response.status === 200) && (!response.data.errors)){
|
||||
setJwt(response.data.token);
|
||||
setExpiration(new Date(JSON.parse(atob(response.data.token.split(".")[1])).exp * 1000));
|
||||
const decodedToken = JSON.parse(atob(response.data.token.split(".")[1]));
|
||||
//console.log("decodedToken = ");
|
||||
//console.log(decodedToken);
|
||||
setExpiration(new Date(decodedToken.exp * 1000));
|
||||
setFirstFetch(false);
|
||||
setAccountId(decodedToken.accountId);
|
||||
return response.data.token;
|
||||
}
|
||||
//If the token cannot be retrieved
|
||||
@@ -90,8 +97,10 @@ export function AuthProvider({
|
||||
jwt,
|
||||
setJwt,
|
||||
expiration,
|
||||
setExpiration
|
||||
}), [ jwt, setJwt, expiration, setExpiration ]);
|
||||
setExpiration,
|
||||
accountId
|
||||
}), [ jwt, setJwt, expiration, setExpiration, accountId ]);
|
||||
|
||||
|
||||
//TODO: Return a spinner while the first token is being fetched
|
||||
if(firstFetch){
|
||||
|
||||
Reference in New Issue
Block a user