v3: added index default tab selection setting, fixed notification pages not loading, reduced invite token length, global player state survives page reloads, many visual fixes
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 44s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 44s
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useContext } from "react";
|
||||
import { useCallback, useContext } from "react";
|
||||
|
||||
import { AuthContext } from "../contexts/AuthContext.ts";
|
||||
|
||||
@@ -16,17 +16,20 @@ function isTokenExpired(token: string): boolean {
|
||||
export const useAuth = () => {
|
||||
const { authResponse, setAuthResponse } = useContext(AuthContext);
|
||||
|
||||
const login = (response: AuthResponse) => {
|
||||
const login = useCallback((response: AuthResponse) => {
|
||||
setAuthResponse(response);
|
||||
localStorage.setItem("authResponse", JSON.stringify(response));
|
||||
};
|
||||
}, [setAuthResponse]);
|
||||
|
||||
const logout = () => {
|
||||
const logout = useCallback(() => {
|
||||
setAuthResponse(null);
|
||||
localStorage.removeItem("authResponse");
|
||||
};
|
||||
}, [setAuthResponse]);
|
||||
|
||||
const authFetch = async (input: RequestInfo, init: RequestInit = {}) => {
|
||||
const authFetch = useCallback(async (
|
||||
input: RequestInfo,
|
||||
init: RequestInit = {},
|
||||
) => {
|
||||
const token = authResponse?.token;
|
||||
|
||||
if (token && isTokenExpired(token)) {
|
||||
@@ -54,7 +57,7 @@ export const useAuth = () => {
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
}, [authResponse?.token, logout]);
|
||||
|
||||
return {
|
||||
user: authResponse?.user ?? null,
|
||||
|
||||
Reference in New Issue
Block a user