Next.js Discord

Discord Forum

Next-Auth authenticated "auth" is always null, despite session existing

Unanswered
Matt posted this in #help-forum
Open in Discord
I'm following the tutorial for adding Auth (https://nextjs.org/learn/dashboard-app/adding-authentication) but my authenticated function always returns false even after logging in.

In other server components, I can log in and access the auth() method which returns the session normally.

import NextAuth from 'next-auth';
import authConfig from '@/auth.config';

export default authConfig.auth;

export const config = {
  // https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};

My middleware is in /src and looks like this ^

8 Replies

Pacific sand lance
i am no help but I am doing the tutorial too and have the same issue
Good to know I'm not alone 😂
@Pacific sand lance I may have found it. Try adding NEXTAUTH_URL=http://localhost:3000 to your .env
Pacific sand lance
hey thx, that worked. but i made it NEXTAUTH_URL="http://localhost:3000/api" idk if that made a difference.
😄
glad we're getting closer!
@Matt