diff --git a/apps/web/app/editor/course/[courseid]/activity/[activityid]/edit/page.tsx b/apps/web/app/editor/course/[courseid]/activity/[activityid]/edit/page.tsx index 8a799264..3f40f150 100644 --- a/apps/web/app/editor/course/[courseid]/activity/[activityid]/edit/page.tsx +++ b/apps/web/app/editor/course/[courseid]/activity/[activityid]/edit/page.tsx @@ -1,5 +1,5 @@ import { default as React, } from "react"; -import AuthProvider from "@components/Security/AuthProvider"; +import AuthProvider from "@components/Security/AuthProviderDepreceated"; import EditorWrapper from "@components/Objects/Editor/EditorWrapper"; import { getCourseMetadataWithAuthHeader } from "@services/courses/courses"; import { cookies } from "next/headers"; diff --git a/apps/web/app/organizations/page.tsx b/apps/web/app/organizations/page.tsx index e2654448..009c0b19 100644 --- a/apps/web/app/organizations/page.tsx +++ b/apps/web/app/organizations/page.tsx @@ -5,7 +5,7 @@ import { deleteOrganizationFromBackend } from "@services/organizations/orgs"; import useSWR, { mutate } from "swr"; import { swrFetcher } from "@services/utils/ts/requests"; import { getAPIUrl, getUriWithOrg } from "@services/config/config"; -import AuthProvider from "@components/Security/AuthProvider"; +import AuthProvider from "@components/Security/AuthProviderDepreceated"; const Organizations = () => { const { data: organizations, error } = useSWR(`${getAPIUrl()}orgs/user/page/1/limit/10`, swrFetcher) diff --git a/apps/web/app/orgs/[orgslug]/(withmenu)/layout.tsx b/apps/web/app/orgs/[orgslug]/(withmenu)/layout.tsx index 5fa03f6a..41853379 100644 --- a/apps/web/app/orgs/[orgslug]/(withmenu)/layout.tsx +++ b/apps/web/app/orgs/[orgslug]/(withmenu)/layout.tsx @@ -1,6 +1,6 @@ import "@styles/globals.css"; import { Menu } from "@components/Objects/Menu/Menu"; -import AuthProvider from "@components/Security/AuthProvider"; +import AuthProvider from "@components/Security/AuthProviderDepreceated"; export default function RootLayout({ children, params }: { children: React.ReactNode , params :any}) { return ( diff --git a/apps/web/app/orgs/[orgslug]/dash/layout.tsx b/apps/web/app/orgs/[orgslug]/dash/layout.tsx index b651d773..eb181267 100644 --- a/apps/web/app/orgs/[orgslug]/dash/layout.tsx +++ b/apps/web/app/orgs/[orgslug]/dash/layout.tsx @@ -1,5 +1,5 @@ import LeftMenu from '@components/Dashboard/UI/LeftMenu' -import AuthProvider from '@components/Security/AuthProvider' +import AuthProvider from '@components/Security/AuthProviderDepreceated' import React from 'react' function DashboardLayout({ children, params }: { children: React.ReactNode, params: any }) { diff --git a/apps/web/app/orgs/[orgslug]/layout.tsx b/apps/web/app/orgs/[orgslug]/layout.tsx index d43311a0..ce0f624f 100644 --- a/apps/web/app/orgs/[orgslug]/layout.tsx +++ b/apps/web/app/orgs/[orgslug]/layout.tsx @@ -1,5 +1,6 @@ 'use client'; import { OrgProvider } from "@components/Contexts/OrgContext"; +import AuthProvider from "@components/Security/AuthContext"; import { getAPIUrl } from "@services/config/config"; import { swrFetcher } from "@services/utils/ts/requests"; import "@styles/globals.css"; @@ -8,10 +9,12 @@ import useSWR from "swr"; export default function RootLayout({ children, params }: { children: React.ReactNode, params: any }) { return ( -
+
+ - {children} - -
+ {children} + + +
); } diff --git a/apps/web/app/orgs/[orgslug]/settings/account/passwords/passwords.tsx b/apps/web/app/orgs/[orgslug]/settings/account/passwords/passwords.tsx index 1b231b70..7f1d2028 100644 --- a/apps/web/app/orgs/[orgslug]/settings/account/passwords/passwords.tsx +++ b/apps/web/app/orgs/[orgslug]/settings/account/passwords/passwords.tsx @@ -1,5 +1,5 @@ "use client"; -import { AuthContext } from '@components/Security/AuthProvider'; +import { AuthContext } from '@components/Security/AuthProviderDepreceated'; import React, { useEffect } from 'react' import { Formik, Form, Field, ErrorMessage } from 'formik'; import { updatePassword } from '@services/settings/password'; diff --git a/apps/web/app/orgs/[orgslug]/settings/account/profile/profile.tsx b/apps/web/app/orgs/[orgslug]/settings/account/profile/profile.tsx index 8423de4f..d7a63ba5 100644 --- a/apps/web/app/orgs/[orgslug]/settings/account/profile/profile.tsx +++ b/apps/web/app/orgs/[orgslug]/settings/account/profile/profile.tsx @@ -1,5 +1,5 @@ "use client"; -import { AuthContext } from '@components/Security/AuthProvider'; +import { AuthContext } from '@components/Security/AuthProviderDepreceated'; import React, { useEffect } from 'react' import { Formik, Form, Field, ErrorMessage } from 'formik'; import { updateProfile } from '@services/settings/profile'; diff --git a/apps/web/app/orgs/[orgslug]/settings/layout.tsx b/apps/web/app/orgs/[orgslug]/settings/layout.tsx index b5e4a401..b52b99d5 100644 --- a/apps/web/app/orgs/[orgslug]/settings/layout.tsx +++ b/apps/web/app/orgs/[orgslug]/settings/layout.tsx @@ -3,7 +3,7 @@ import React, { createContext, useState } from 'react' import { styled } from '@stitches/react'; import Link from 'next/link'; import LearnHouseWhiteLogo from '@public/learnhouse_text_white.png'; -import AuthProvider, { AuthContext } from '@components/Security/AuthProvider'; +import AuthProvider, { AuthContext } from '@components/Security/AuthProviderDepreceated'; import Avvvatars from 'avvvatars-react'; import Image from 'next/image'; import AuthenticatedClientElement from '@components/Security/AuthenticatedClientElement'; diff --git a/apps/web/components/Dashboard/UI/LeftMenu.tsx b/apps/web/components/Dashboard/UI/LeftMenu.tsx index fc563d71..a4bac0f1 100644 --- a/apps/web/components/Dashboard/UI/LeftMenu.tsx +++ b/apps/web/components/Dashboard/UI/LeftMenu.tsx @@ -1,33 +1,67 @@ 'use client'; import { useOrg } from '@components/Contexts/OrgContext'; +import { useAuth } from '@components/Security/AuthContext'; import ToolTip from '@components/StyledElements/Tooltip/Tooltip' -import { ArrowLeft, Book, Home } from 'lucide-react' +import LearnHouseDashboardLogo from '@public/dashLogo.png'; +import Avvvatars from 'avvvatars-react'; +import { ArrowLeft, Book, Home, Settings } from 'lucide-react' +import Image from 'next/image'; import Link from 'next/link' import React, { use, useEffect } from 'react' function LeftMenu() { const org = useOrg() as any; + const auth = useAuth() as any; + const [loading, setLoading] = React.useState(true); + + function waitForEverythingToLoad() { + if (org && auth) { + return true; + } + return false; + } useEffect(() => { - + if (waitForEverythingToLoad()) { + setLoading(false); + } } - , [org]) + , [loading]) return (
-
- - - - - - - - - + className='flex flex-col w-24 bg-black h-screen text-white shadow-xl'> +
+
+ + Learnhouse logo + +
+
+ + + + + + + + + +
+
+ + + +
+
+ +
+
+
{auth.user.username}
+ +
diff --git a/apps/web/components/Objects/Editor/Editor.tsx b/apps/web/components/Objects/Editor/Editor.tsx index a7d6b319..8b5dfb80 100644 --- a/apps/web/components/Objects/Editor/Editor.tsx +++ b/apps/web/components/Objects/Editor/Editor.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useEditor, EditorContent } from "@tiptap/react"; import StarterKit from "@tiptap/starter-kit"; -import { AuthContext } from "../../Security/AuthProvider"; +import { AuthContext } from "../../Security/AuthProviderDepreceated"; import learnhouseIcon from "public/learnhouse_icon.png"; import { ToolbarButtons } from "./Toolbar/ToolbarButtons"; import { motion } from "framer-motion"; diff --git a/apps/web/components/Objects/Modals/Feedback/Feedback.tsx b/apps/web/components/Objects/Modals/Feedback/Feedback.tsx index a4621d33..7276adea 100644 --- a/apps/web/components/Objects/Modals/Feedback/Feedback.tsx +++ b/apps/web/components/Objects/Modals/Feedback/Feedback.tsx @@ -4,7 +4,7 @@ import * as Form from '@radix-ui/react-form' import React, { useState } from "react"; import * as Sentry from '@sentry/browser'; import { CheckCircleIcon } from "lucide-react"; -import { AuthContext } from "@components/Security/AuthProvider"; +import { AuthContext } from "@components/Security/AuthProviderDepreceated"; import { randomUUID } from "crypto"; export const FeedbackModal = (user: any) => { diff --git a/apps/web/components/Security/AuthContext.tsx b/apps/web/components/Security/AuthContext.tsx new file mode 100644 index 00000000..a1742832 --- /dev/null +++ b/apps/web/components/Security/AuthContext.tsx @@ -0,0 +1,58 @@ +import { getNewAccessTokenUsingRefreshToken, getUserInfo } from '@services/auth/auth'; +import { getAPIUrl } from '@services/config/config'; +import { swrFetcher } from '@services/utils/ts/requests'; +import React, { useEffect } from 'react' +import useSWR from 'swr'; + +const AuthContext = React.createContext({}) + +type Auth = { + access_token: string; + isAuthenticated: boolean; + user: any; +} + +function AuthProvider({ children, orgslug }: { children: React.ReactNode, orgslug: string }) { + const [auth, setAuth] = React.useState({ access_token: "", isAuthenticated: false, user: {} }); + + async function checkRefreshToken() { + //deleteCookie("access_token_cookie"); + let data = await getNewAccessTokenUsingRefreshToken(); + if (data) { + return data.access_token; + } + } + + async function checkAuth() { + try { + let access_token = await checkRefreshToken(); + let userInfo = {}; + + if (access_token) { + userInfo = await getUserInfo(access_token); + setAuth({ access_token: access_token, isAuthenticated: true, user: userInfo }); + + } else { + setAuth({ access_token: access_token, isAuthenticated: false, user: userInfo }); + } + } catch (error) { + console.log(error); + } + } + + useEffect(() => { + checkAuth(); + }, []) + + return ( + + {children} + + ) +} + +export function useAuth() { + return React.useContext(AuthContext); +} + +export default AuthProvider \ No newline at end of file diff --git a/apps/web/components/Security/AuthProvider.tsx b/apps/web/components/Security/AuthProviderDepreceated.tsx similarity index 100% rename from apps/web/components/Security/AuthProvider.tsx rename to apps/web/components/Security/AuthProviderDepreceated.tsx diff --git a/apps/web/components/Security/AuthenticatedClientElement.tsx b/apps/web/components/Security/AuthenticatedClientElement.tsx index 602a3b2c..693aafec 100644 --- a/apps/web/components/Security/AuthenticatedClientElement.tsx +++ b/apps/web/components/Security/AuthenticatedClientElement.tsx @@ -1,6 +1,6 @@ 'use client'; import React from "react"; -import { AuthContext } from "./AuthProvider"; +import { AuthContext } from "./AuthProviderDepreceated"; import useSWR, { mutate } from "swr"; import { getAPIUrl } from "@services/config/config"; import { swrFetcher } from "@services/utils/ts/requests"; diff --git a/apps/web/components/Security/HeaderProfileBox.tsx b/apps/web/components/Security/HeaderProfileBox.tsx index 40752735..6f712198 100644 --- a/apps/web/components/Security/HeaderProfileBox.tsx +++ b/apps/web/components/Security/HeaderProfileBox.tsx @@ -2,7 +2,7 @@ import React from "react"; import styled from "styled-components"; import Link from "next/link"; -import { AuthContext } from "./AuthProvider"; +import { AuthContext } from "./AuthProviderDepreceated"; import Avvvatars from "avvvatars-react"; import { GearIcon } from "@radix-ui/react-icons"; diff --git a/apps/web/public/dashLogo.png b/apps/web/public/dashLogo.png new file mode 100644 index 00000000..c05773c2 Binary files /dev/null and b/apps/web/public/dashLogo.png differ