User Auth Handling Update
This commit is contained in:
@@ -16,7 +16,7 @@ export default function RootLayout({
|
|||||||
<main className="max-h-screen max-w-screen bg-img overflow-hidden" suppressHydrationWarning={true}>
|
<main className="max-h-screen max-w-screen bg-img overflow-hidden" suppressHydrationWarning={true}>
|
||||||
{!isMobile && !isSafari ? <NavBar /> : null}
|
{!isMobile && !isSafari ? <NavBar /> : null}
|
||||||
<section className="space-x-2 gap-4 flex flex-col overflow-y-auto h-screen p-4 lg:p-6 lg:rounded-xl lg:shadow-sm">
|
<section className="space-x-2 gap-4 flex flex-col overflow-y-auto h-screen p-4 lg:p-6 lg:rounded-xl lg:shadow-sm">
|
||||||
<img src="/drinkhappylogo.png" alt="Drink Happy Logo Image" className="h-auto mx-auto w-3/4 lg:w-1/4" />
|
<img src="/drinkhappylogo.png" alt="Drink Happy Logo Image" className="h-auto mx-auto w-3/4 lg:w-2/3" />
|
||||||
{children}
|
{children}
|
||||||
</section>
|
</section>
|
||||||
{isMobile && isSafari ? (
|
{isMobile && isSafari ? (
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ function Mobile() {
|
|||||||
return (
|
return (
|
||||||
<main className="flex flex-col gap-[32px] row-start-2 items-center mt-10">
|
<main className="flex flex-col gap-[32px] row-start-2 items-center mt-10">
|
||||||
<h1 className="text-3xl sm:text-4xl font-bold tracking-[-.01em] text-center sm:text-left">
|
<h1 className="text-3xl sm:text-4xl font-bold tracking-[-.01em] text-center sm:text-left">
|
||||||
Welcome, {isAuthenticated ? session.username : ""} !!
|
{isAuthenticated ? `Welcome, ${session.username} !!` : ""}
|
||||||
</h1>
|
</h1>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
@@ -20,7 +20,7 @@ function Web() {
|
|||||||
return (
|
return (
|
||||||
<main className="flex flex-col row-start-2 items-center mt-10">
|
<main className="flex flex-col row-start-2 items-center mt-10">
|
||||||
<h1 className="text-3xl sm:text-4xl font-bold tracking-[-.01em] text-center sm:text-left">
|
<h1 className="text-3xl sm:text-4xl font-bold tracking-[-.01em] text-center sm:text-left">
|
||||||
Welcome, {isAuthenticated ? session.username : ""} !!
|
{isAuthenticated ? `Welcome, ${session.username} !!` : ""}
|
||||||
</h1>
|
</h1>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export async function GET() {
|
|||||||
const session = await auth0.getSession();
|
const session = await auth0.getSession();
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return NextResponse.json({ session: null }, { status: 401 });
|
return NextResponse.json({ session: null }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionUser = session.user;
|
const sessionUser = session.user;
|
||||||
@@ -17,8 +17,6 @@ export async function GET() {
|
|||||||
if (!userData) {
|
if (!userData) {
|
||||||
console.log("User not found in database, creating new user...");
|
console.log("User not found in database, creating new user...");
|
||||||
userData = await db.users.create(sessionUser?.email as string, sessionUser?.nickname as string);
|
userData = await db.users.create(sessionUser?.email as string, sessionUser?.nickname as string);
|
||||||
} else {
|
|
||||||
console.log("User found in database:", userData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json({ session: userData });
|
return NextResponse.json({ session: userData });
|
||||||
|
|||||||
@@ -27,11 +27,7 @@ export const DeviceProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
|||||||
const res = await fetch("/auth/session");
|
const res = await fetch("/auth/session");
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) setSession(data.session);
|
||||||
setSession(data.session);
|
|
||||||
} else {
|
|
||||||
console.error("Error fetching session:", data);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
checkAuthentication();
|
checkAuthentication();
|
||||||
|
|||||||
Reference in New Issue
Block a user