fixed my test page so quizzes are behind login page
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { requireOnboardingComplete } from "@/lib/auth-helpers";
|
||||
|
||||
type AppAuthGateProps = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export async function AppAuthGate({ children }: AppAuthGateProps) {
|
||||
// Temporary: allow guest access while testing app pages from the bottom nav.
|
||||
await requireOnboardingComplete();
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { AppNav } from "@/components/layout/app-nav";
|
||||
import { createClient } from "@/lib/supabase/client";
|
||||
|
||||
export function GlobalBottomNav() {
|
||||
const [showNav, setShowNav] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const supabase = createClient();
|
||||
|
||||
async function syncNavState() {
|
||||
const {
|
||||
data: { user },
|
||||
} = await supabase.auth.getUser();
|
||||
|
||||
setShowNav(
|
||||
!!user && user.user_metadata?.onboarding_completed === true,
|
||||
);
|
||||
}
|
||||
|
||||
void syncNavState();
|
||||
|
||||
const {
|
||||
data: { subscription },
|
||||
} = supabase.auth.onAuthStateChange(() => {
|
||||
void syncNavState();
|
||||
});
|
||||
|
||||
return () => subscription.unsubscribe();
|
||||
}, []);
|
||||
|
||||
if (!showNav) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <AppNav />;
|
||||
}
|
||||
|
||||
@@ -23,25 +23,10 @@ export const appNavItems = [
|
||||
|
||||
export type NavItem = (typeof appNavItems)[number];
|
||||
|
||||
const appPaths = [
|
||||
routes.avatar,
|
||||
routes.habits,
|
||||
routes.dailyQuiz,
|
||||
routes.shop,
|
||||
routes.profile,
|
||||
routes.onboardingQuiz,
|
||||
] as const;
|
||||
|
||||
export function isAuthPath(pathname: string) {
|
||||
return pathname.startsWith("/auth");
|
||||
}
|
||||
|
||||
export function isPublicPath(pathname: string) {
|
||||
return (
|
||||
pathname === routes.home ||
|
||||
isAuthPath(pathname) ||
|
||||
appPaths.some(
|
||||
(path) => pathname === path || pathname.startsWith(`${path}/`),
|
||||
)
|
||||
);
|
||||
return pathname === routes.home || isAuthPath(pathname);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user