Skip to content

Commit

Permalink
Fix: spectator login
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Sep 15, 2024
1 parent 1bc41ec commit 6433472
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/hooks/auth.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { authorizedRoles } from "@/store/api/auth";
import { authUser } from "@/utils";

export const whitelistedPaths = ["login", "forgot-password", "reset-password"];
Expand All @@ -13,7 +14,7 @@ const useAuth = () => {
useEffect(() => {
if (
(!localStorage.getItem("access_token") && !whitelistedPaths.includes(location.pathname.split("/")[1])) ||
(localStorage.getItem("access_token") && authUser()?.role !== "ADMIN")
(localStorage.getItem("access_token") && !authorizedRoles.includes(authUser()?.role))
) {
navigate("/login");
} else if (["/login"].includes(location.pathname) && localStorage.getItem("access_token")) {
Expand Down
2 changes: 1 addition & 1 deletion src/store/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { default as baseQuery, mutationHelper } from "./base";

const { post } = mutationHelper;

const authorizedRoles = ["ADMIN", "SPECTATOR"];
export const authorizedRoles = ["ADMIN", "SPECTATOR"];

export const authApi = createApi({
reducerPath: "authApi",
Expand Down

0 comments on commit 6433472

Please sign in to comment.