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

@ -3,18 +3,16 @@ import React, { createContext, useState } from 'react'
import { styled } from '@stitches/react'; import { styled } from '@stitches/react';
import Link from 'next/link'; import Link from 'next/link';
import LearnHouseWhiteLogo from '@public/learnhouse_text_white.png'; import LearnHouseWhiteLogo from '@public/learnhouse_text_white.png';
import { AuthContext } from '@components/Security/AuthProvider'; import AuthProvider, { AuthContext } from '@components/Security/AuthProvider';
import Avvvatars from 'avvvatars-react'; import Avvvatars from 'avvvatars-react';
import Image from 'next/image'; import Image from 'next/image';
function SettingsLayout({ children, params }: { children: React.ReactNode, params: any }) { function SettingsLayout({ children, params }: { children: React.ReactNode, params: any }) {
const auth: any = React.useContext(AuthContext); const auth: any = React.useContext(AuthContext);
return ( return (
<> <>
<AuthProvider/>
<Main> <Main>
<LeftWrapper> <LeftWrapper>
<LeftTopArea> <LeftTopArea>

View file

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