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 = {
|
type AppAuthGateProps = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function AppAuthGate({ children }: AppAuthGateProps) {
|
export async function AppAuthGate({ children }: AppAuthGateProps) {
|
||||||
// Temporary: allow guest access while testing app pages from the bottom nav.
|
await requireOnboardingComplete();
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,40 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { AppNav } from "@/components/layout/app-nav";
|
import { AppNav } from "@/components/layout/app-nav";
|
||||||
|
import { createClient } from "@/lib/supabase/client";
|
||||||
|
|
||||||
export function GlobalBottomNav() {
|
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 />;
|
return <AppNav />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,25 +23,10 @@ export const appNavItems = [
|
|||||||
|
|
||||||
export type NavItem = (typeof appNavItems)[number];
|
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) {
|
export function isAuthPath(pathname: string) {
|
||||||
return pathname.startsWith("/auth");
|
return pathname.startsWith("/auth");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isPublicPath(pathname: string) {
|
export function isPublicPath(pathname: string) {
|
||||||
return (
|
return pathname === routes.home || isAuthPath(pathname);
|
||||||
pathname === routes.home ||
|
|
||||||
isAuthPath(pathname) ||
|
|
||||||
appPaths.some(
|
|
||||||
(path) => pathname === path || pathname.startsWith(`${path}/`),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user