Skip to content

Commit

Permalink
Merge pull request #6 from ciandt-china-dev/feature/Change-240514
Browse files Browse the repository at this point in the history
Fix siteguard under chat router issue.
  • Loading branch information
Bobz1989 authored May 16, 2024
2 parents 33bf82a + fa405b4 commit e47e8e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions web/app/(commonLayout)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import { AppContextProvider } from '@/context/app-context'
import GA, { GaType } from '@/app/components/base/ga'
import HeaderWrapper from '@/app/components/header/HeaderWrapper'
import Header from '@/app/components/header'
import SiteGuard from '@/app/components/site-guard'
import { EventEmitterContextProvider } from '@/context/event-emitter'
import { ProviderContextProvider } from '@/context/provider-context'
import { ModalContextProvider } from '@/context/modal-context'

const Layout = ({ children }: { children: ReactNode }) => {
return (
<>
<SiteGuard/>
<GA gaType={GaType.admin} />
<SwrInitor>
<AppContextProvider>
Expand Down
2 changes: 2 additions & 0 deletions web/app/(shareLayout)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react'
import type { FC } from 'react'
import GA, { GaType } from '@/app/components/base/ga'
import SiteGuard from '../components/site-guard'

const Layout: FC<{
children: React.ReactNode
}> = ({ children }) => {
return (
<div className="min-w-[300px] h-full pb-[env(safe-area-inset-bottom)]">
<GA gaType={GaType.webapp} />
<SiteGuard />
{children}
</div>
)
Expand Down
10 changes: 5 additions & 5 deletions web/app/components/site-guard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use client'
import React, { memo, useEffect, useState } from 'react';
import React, { memo, useEffect, useState, useRef } from 'react';
import { usePathname } from 'next/navigation';

const SiteGuard = () => {
const router = usePathname();
const [isAuthenticated, setIsAuthenticated] = useState(false);
const [isCheckingAuth, setIsCheckingAuth] = useState(true);
const [promptShown, setPromptShown] = useState(false);
const promptShown = useRef(false);

useEffect(() => {
const checkAuth = async () => {
if (router.startsWith('/chat') && !promptShown) {
if (router.startsWith('/chat') && !promptShown.current) {
const password = prompt('Enter password:');
setPromptShown(true);
promptShown.current = true;

if (password === 'cit2024') {
setIsAuthenticated(true);
Expand All @@ -27,7 +27,7 @@ const SiteGuard = () => {
};

checkAuth();
}, [router, promptShown]);
}, [router]);

if (isCheckingAuth) {
return <div style={{ height: '100vh', backgroundColor: 'white' }} />;
Expand Down

0 comments on commit e47e8e4

Please sign in to comment.