mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: add settings page to private routes
This commit is contained in:
parent
6137c907d2
commit
b4bd9f8cd3
2 changed files with 6 additions and 8 deletions
|
|
@ -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) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue