mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: use session access_tokens
This commit is contained in:
parent
08cc97f557
commit
52f2235942
74 changed files with 413 additions and 440 deletions
|
|
@ -1,9 +1,9 @@
|
|||
'use client';
|
||||
import React, { useEffect, useState, useCallback, useMemo } from 'react';
|
||||
import { useOrg } from '@components/Contexts/OrgContext';
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext';
|
||||
import useAdminStatus from '@components/Hooks/useAdminStatus';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import PageLoading from '@components/Objects/Loaders/PageLoading';
|
||||
|
||||
type AuthorizationProps = {
|
||||
children: React.ReactNode;
|
||||
|
|
@ -30,10 +30,19 @@ const AdminAuthorization: React.FC<AuthorizationProps> = ({ children, authorizat
|
|||
const isUserAuthenticated = useMemo(() => session.status === 'authenticated', [session.status]);
|
||||
|
||||
const checkPathname = useCallback((pattern: string, pathname: string) => {
|
||||
const regexPattern = new RegExp(`^${pattern.replace(/\//g, '\\/').replace(/\*/g, '.*')}$`);
|
||||
// Ensure the inputs are strings
|
||||
if (typeof pattern !== 'string' || typeof pathname !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert pattern to a regex pattern
|
||||
const regexPattern = new RegExp(`^${pattern.replace(/[\/.*+?^${}()|[\]\\]/g, '\\$&').replace(/\\\*/g, '.*')}$`);
|
||||
|
||||
// Test the pathname against the regex pattern
|
||||
return regexPattern.test(pathname);
|
||||
}, []);
|
||||
|
||||
|
||||
const isAdminPath = useMemo(() => ADMIN_PATHS.some(path => checkPathname(path, pathname)), [pathname, checkPathname]);
|
||||
|
||||
const authorizeUser = useCallback(() => {
|
||||
|
|
@ -69,7 +78,7 @@ const AdminAuthorization: React.FC<AuthorizationProps> = ({ children, authorizat
|
|||
if (loading) {
|
||||
return (
|
||||
<div className="flex justify-center items-center h-screen">
|
||||
<h1 className="text-2xl">Loading...</h1>
|
||||
<PageLoading />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue