Skip to content

Commit

Permalink
fix: correctly reload page
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Dec 7, 2024
1 parent 219d3ec commit 74b5282
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cr-vif/frontend",
"private": true,
"version": "0.1.0",
"version": "0.2.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
7 changes: 4 additions & 3 deletions packages/frontend/src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useQuery } from "@tanstack/react-query";
import { api, setToken, type RouterOutputs } from "../api";

const initialAuth = safeParseLocalStorage("crvif/auth");
if (!initialAuth) localStorage.setItem("crvif/version", "1");
setToken(initialAuth?.token);

const AuthContext = createContext<AuthContextProps>({
Expand All @@ -16,12 +17,12 @@ const AuthContext = createContext<AuthContextProps>({
export const AuthProvider = ({ children }: PropsWithChildren) => {
const [data, setData] = useState<Omit<AuthContextProps, "setData">>(initialAuth);

const logout = useLogout();

useEffect(() => {
const version = localStorage.getItem("crvif/version");
if (!version) {
return logout();
localStorage.removeItem("crvif/auth");
localStorage.setItem("crvif/version", "1");
window.location.reload();
}
}, []);

Expand Down

0 comments on commit 74b5282

Please sign in to comment.