#Page flashing before authentication
62 messages ยท Page 1 of 1 (latest)
๐ This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
๐ต๏ธ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
โ
You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
middleware.ts ```jsx
export { default } from "next-auth/middleware";
flashing page : ```jsx
import { getSortedPostsData } from "@/utils/posts";
import { BlogTile } from "../components/BlogTile";
export default async () => {
const allPostsData = await getSortedPostsData();
return (
<div className="h-full flex flex-col space-y-20">
<div className="text-center text-5xl">All Blogs</div>
<div className="grid grid-flow-row gap-5 decoration-0 grid-cols-4 h-full grid-rows-3">
{allPostsData.map(({ id, date, title, about }) => (
<BlogTile key={id} id={id} title={title} date={date} about={about} />
))}
</div>
</div>
);
};
Blog tile component : ```jsx
import { PostsMetadata } from "../../utils/posts";
import Link from "next/link";
export const BlogTile = ({ id, title, date, about }: PostsMetadata) => {
return (
<Link
href={/posts/${id}}
className="col-span-1 row-span-1 dark:bg-slate-600 bg-slate-300"
>
<div
className="items-center h-full justify-center flex flex-col space-y-10 p-10 decoration-0"
>
<div className="flex flex-col items-start">
<div className="font-bold text-lg">{title}</div>
<div className="text-sm mt-3">Created: {date}</div>
</div>
<div className="font-semibold">{about}</div>
</div>
</Link>
);
};
when i try to go to http://localhost:3000/posts i see the contents of posts for a sec and then get redirected to signin page of next-auth
this is when no session is there
In my opinion, it might not be the middleware flashing the page tbh
then what ?
how can middleware allow to show contents of page if no session is there ๐ค
Just in case. Try disabling the middleware
We trying to fix your flashing page here
So im just trynna see where the problem is at
i mean if you disable middleware it will just show the contents of the posts page
without redirecting to signin
Didn't nextjs docs address this very issue?
"prevent flash of unauthenticated content"
I'll get it 1 sec
Find in page "flash of unauthenticated content"
Thats for pages?
Oh my bad lol
Maybe i just dont know this enough but that literally shouldn't happen unless that middleware provided by nextauth has a problem.
The middleware is handled before rendering of the pages iirc
Yeah I was gonna suggest that
Or maybe it caches your previous session the revalidates it at the point it flashes
Try clerk
i think it's related so me passing SessionProvider in layout component
i am trying few things and i'll let you know if i fix it
No no session provider should be in layout tho
So that shouldn't be an issue
ya issue is with my middleware , it's not working actually at all ๐คฃ
prolly i am doing some dumb stuff
Where is your middleware lol
How is middleware not working ๐คจ
inside app folder
Middleware should be in the same directory as package.json
Hm....
It should be at the same level as app folder
It should be in ur root dir
ya working fine now , skill issue , i am noob
๐ญ
This
@bitter ocean league of legends PTSD flashbacks
stupid logout button was redirecting me to singin page apparently
i feel too embarassed to stay online anymore
thanks for help @stuck rune @uneven island
๐
middleware
it wasn't working at all , i commented out my signout button and i was not getting to the signin page ๐คฃ
"use client";
import { signOut, useSession } from "next-auth/react";
import { redirect } from "next/navigation";
export const SignoutButton = () => {
const { status } = useSession();
if (status === "unauthenticated") {
return redirect("/api/auth/signin");
}
return (
<div>
<button
onClick={() => {
console.log("here");
signOut();
}}
>
Signout
</button>
</div>
);
};
so this basically flashed the page on client and then waits for session api to complete and then redirected me
Anyways mark the answer
how ?
.