feat: add settings page to private routes

This commit is contained in:
swve 2023-04-09 01:45:57 +02:00
parent 6137c907d2
commit b4bd9f8cd3
2 changed files with 6 additions and 8 deletions

View file

@ -5,7 +5,7 @@ import { useRouter, usePathname } from "next/navigation";
export const AuthContext: any = React.createContext({});
const PRIVATE_ROUTES = ["/course/*/edit",];
const PRIVATE_ROUTES = ["/course/*/edit", "/settings*"];
const NON_AUTHENTICATED_ROUTES = ["/login", "/register"];
export interface Auth {
@ -48,7 +48,7 @@ const AuthProvider = ({ children }: any) => {
} else {
setAuth({ access_token, isAuthenticated: false, userInfo, isLoading });
// Redirect to login if user is trying to access a private route
if (PRIVATE_ROUTES.some((route) => new RegExp(`^${route.replace("*", ".*")}$`).test(pathname))) {
router.push("/login");
@ -56,7 +56,7 @@ const AuthProvider = ({ children }: any) => {
}
} catch (error) {
}
}