diff --git a/src/app/gateway/page.tsx b/src/app/gateway/page.tsx
new file mode 100644
index 0000000..6be0471
--- /dev/null
+++ b/src/app/gateway/page.tsx
@@ -0,0 +1,46 @@
+'use client';
+
+import Load from '@/components/loading/loading';
+import { useAuth } from '@/contexts/auth';
+import { useSearchParams } from 'next/navigation';
+import React from 'react';
+
+const pages = {
+ member: {
+ home: '/',
+ qr: '/qr',
+ profile: '/edit',
+ },
+ staff: {
+ home: '/',
+ qr: '/staff/qr',
+ profile: '/edit',
+ },
+ admin: {
+ home: '/',
+ qr: '/staff/qr',
+ profile: '/admin/dashboard',
+ },
+};
+
+export default function Page() {
+ const { user, isInitialized } = useAuth();
+ const searchParams = useSearchParams();
+ const page = searchParams.get('page') || 'home';
+
+ if (!isInitialized) {
+ return ;
+ }
+
+ window.location.href =
+ pages[user?.role || 'member'][page as 'home' | 'qr' | 'profile'];
+ return ;
+}
+
+function Loading() {
+ return (
+
+
+
+ );
+}
diff --git a/src/components/protect.tsx b/src/components/protect.tsx
index 892889c..923d8d4 100644
--- a/src/components/protect.tsx
+++ b/src/components/protect.tsx
@@ -18,10 +18,10 @@ export default function Protect({
children,
callBack = '/',
}: ProtectProps) {
- const { user, isLoggingIn, isInitialized } = useAuth();
+ const { user, isInitialized } = useAuth();
const router = useRouter();
- if (isLoggingIn || !isInitialized) {
+ if (!isInitialized) {
return ;
}
diff --git a/src/contexts/auth.tsx b/src/contexts/auth.tsx
index cb04290..4c79949 100644
--- a/src/contexts/auth.tsx
+++ b/src/contexts/auth.tsx
@@ -73,7 +73,6 @@ export default function AuthProvider({ children }: { children: ReactNode }) {
return { success: false, error: error };
}
- console.log('start login');
set('isLoggingIn', true);
const loginResp = await sendLogin(userId);
@@ -139,8 +138,10 @@ export default function AuthProvider({ children }: { children: ReactNode }) {
}
useEffect(() => {
- login();
- set('isInitialized', true);
+ (async () => {
+ await login();
+ set('isInitialized', true);
+ })();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);