Next.js Discord

Discord Forum

Auth object(user) is lost when code changes in development

Unanswered
Selkirk Rex posted this in #help-forum
Open in Discord
Selkirk RexOP
export default async function ProfileLayout({ children }: LayoutProps) {
  const user = await getUser();

  if (!user) redirect("/");

As u see here i have fairly simple code, in development its so annoying when user object is lost because its redirected to home page and even when i clicking from navbar to go to this page it stillredirect me, i dont know how can i fix this

14 Replies

Selkirk RexOP
export const getUser = cache(async () => {
  try {
    const { getUser: _getKindeUser } = getKindeServerSession();
    const kindeUser = await _getKindeUser();
    if (!kindeUser) {
      throw new Error("Kinde user not found");
    }
    const dbUser = await db.user.findUnique({
      where: { email: kindeUser.email || "" },
    });

    return dbUser;
  } catch (error) {
    // console.error(error);
    return null;
  }
});
Sun bear
what are you using for the authentication?
Selkirk RexOP
kinde auth
as u see here
and google oauth fully managed by kinde
u think kinde loses the user object
i mean its not like when i save code
after a few saves this i am automatically redirected to home page
i logged the error as well
Sun bear
yeah, I've never had this issue happen to me before in other auth providers i've used.
Selkirk RexOP
hmm, yep thats okay