NextJs with next-auth login problem

Hello,

Can you help me with this little problem ?

I have this site with this deploy URL https://deploy-preview-17--farmer-conversations-analysis.netlify.app/

I have to be authenticated in order to access the conversations view.

When i sign in the session is created but i’m not redirected to the requested page. I stay on the login page.

When i visit this page i can see that the session is created https://deploy-preview-17--farmer-conversations-analysis.netlify.app/api/session

This works on my local env i even tried on vercel and it works there too.

See below for the build logs

9:02:26 AM: Netlify Build
9:02:26 AM: ────────────────────────────────────────────────────────────────
9:02:26 AM: ​
9:02:26 AM: ❯ Version
9:02:26 AM: @netlify/build 29.21.1
9:02:26 AM: ​
9:02:26 AM: ❯ Flags
9:02:26 AM: baseRelDir: true
9:02:26 AM: buildId: 651a6ad6466dad00073f3977
9:02:26 AM: deployId: 651a6ad6466dad00073f3979
9:02:26 AM: ​
9:02:26 AM: ❯ Current directory
9:02:26 AM: /opt/build/repo
9:02:26 AM: ​
9:02:26 AM: ❯ Config file
9:02:26 AM: /opt/build/repo/netlify.toml
9:02:26 AM: ​
9:02:26 AM: ❯ Context
9:02:26 AM: deploy-preview
9:02:26 AM: ​
9:02:26 AM: ❯ Using Next.js Runtime - v4.40.1
9:02:27 AM: ​
9:02:27 AM: @netlify/plugin-nextjs (onPreBuild event)
9:02:27 AM: ────────────────────────────────────────────────────────────────
9:02:27 AM: ​
9:02:27 AM: Next.js cache restored.
9:02:27 AM: Netlify configuration property “build.environment.NEXT_PRIVATE_TARGET” value changed.
9:02:27 AM: ​
9:02:27 AM: (@netlify/plugin-nextjs onPreBuild completed in 165ms)
9:02:27 AM: ​
9:02:27 AM: build.command from netlify.toml
9:02:27 AM: ────────────────────────────────────────────────────────────────
9:02:27 AM: ​
9:02:27 AM: $ npm run build && echo “NEXTAUTH_URL=$DEPLOY_PRIME_URL” > .env.local
9:02:27 AM: > farmer-conversations-analysis@0.1.0 prebuild
9:02:27 AM: > node prebuild.js
9:02:27 AM: > farmer-conversations-analysis@0.1.0 build
9:02:27 AM: > next build
9:02:28 AM: - info Creating an optimized production build…
9:02:43 AM: - info Compiled successfully
9:02:43 AM: - info Linting and checking validity of types…
9:02:45 AM: - info Collecting page data…
9:02:48 AM: - info Generating static pages (0/7)
9:02:48 AM: - info Generating static pages (1/7)
9:02:48 AM: - info Generating static pages (3/7)
9:02:48 AM: - info Generating static pages (5/7)
9:02:48 AM: - info Generating static pages (7/7)
9:02:50 AM: - info Finalizing page optimization…
9:02:50 AM: Route (app) Size First Load JS
9:02:50 AM: ┌ λ / 177 B 83.8 kB
9:02:50 AM: ├ λ /api/auth/[…nextauth] 0 B 0 B
9:02:50 AM: ├ λ /api/auth/signin 1.28 kB 94.9 kB
9:02:50 AM: ├ λ /api/session 0 B 0 B
9:02:50 AM: ├ λ /conversations 2.05 kB 498 kB
9:02:50 AM: ├ λ /conversations/[id] 3.15 kB 309 kB
9:02:50 AM: ├ λ /conversations/[id]/messages/[messageId] 127 kB 438 kB
9:02:50 AM: └ ○ /favicon.ico 0 B 0 B
9:02:50 AM: + First Load JS shared by all 77.8 kB
9:02:50 AM: ├ chunks/698-8f6267edb1325894.js 25.3 kB
9:02:50 AM: ├ chunks/bce60fc1-b8680730fde16ccc.js 50.5 kB
9:02:50 AM: ├ chunks/main-app-a1d589289c20eea2.js 220 B
9:02:50 AM: └ chunks/webpack-a0fad87709855467.js 1.78 kB
9:02:50 AM: Route (pages) Size First Load JS
9:02:50 AM: ─ ○ /404 183 B 75.6 kB
9:02:50 AM: + First Load JS shared by all 75.4 kB
9:02:50 AM: ├ chunks/framework-27a02ad0dce83268.js 1.79 kB
9:02:50 AM: ├ chunks/main-4bc5cda1ba7eb73b.js 71.7 kB
9:02:50 AM: ├ chunks/pages/_app-4e72088c2da7d84b.js 198 B
9:02:50 AM: └ chunks/webpack-a0fad87709855467.js 1.78 kB
9:02:50 AM: ƒ Middleware 52.6 kB
9:02:50 AM: λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
9:02:50 AM: ○ (Static) automatically rendered as static HTML (uses no initial props)
9:02:50 AM: ​
9:02:50 AM: (build.command completed in 22.4s)
9:02:50 AM: ​
9:02:50 AM: @netlify/plugin-nextjs (onBuild event)
9:02:50 AM: ────────────────────────────────────────────────────────────────
9:02:50 AM: ​
9:02:50 AM: NextAuth package detected, setting NEXTAUTH_URL environment variable to https://deploy-preview-17--farmer-conversations-analysis.netlify.app
9:02:50 AM: Moving static page files to serve from CDN…
9:02:50 AM: Moved 2 files
9:02:50 AM: You are not using Netlify Edge Functions for image format detection. Set env var “NEXT_FORCE_EDGE_IMAGES=true” to enable.
9:02:50 AM: :sparkles: Deploying middleware and functions to Netlify Edge Functions :sparkles:
9:02:50 AM: Netlify configuration property “redirects” value changed to [
9:02:50 AM: { from: “/next/static/", to: “/static/:splat”, status: 200 },
9:02:50 AM: {
9:02:50 AM: from: "/_next/image
",
9:02:50 AM: query: { url: “:url”, w: “:width”, q: “:quality” },
9:02:50 AM: to: "/ipx/w:width,q
:quality/:url”,
9:02:50 AM: status: 301
9:02:50 AM: },
9:02:50 AM: { from: “/_ipx/", to: “/.netlify/builders/_ipx”, status: 200 },
9:02:50 AM: {
9:02:50 AM: from: "/api/
”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/mkulimaGPT.svg”,
9:02:50 AM: to: “/mkulimaGPT.svg”,
9:02:50 AM: conditions: { Cookie: [Array] },
9:02:50 AM: status: 200
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/next.svg”,
9:02:50 AM: to: “/next.svg”,
9:02:50 AM: conditions: { Cookie: [Array] },
9:02:50 AM: status: 200
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/vercel.svg”,
9:02:50 AM: to: “/vercel.svg”,
9:02:50 AM: conditions: { Cookie: [Array] },
9:02:50 AM: status: 200
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/",
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200,
9:02:50 AM: conditions: { Cookie: [Array] },
9:02:50 AM: force: true
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/_next/data/JOLqHbHezIh6MvxXn2nmo/index.json”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200,
9:02:50 AM: force: false
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200,
9:02:50 AM: force: false
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/_next/data/JOLqHbHezIh6MvxXn2nmo/conversations.json”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200,
9:02:50 AM: force: false
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/conversations”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200,
9:02:50 AM: force: false
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/_next/data/JOLqHbHezIh6MvxXn2nmo/conversations/:id.json”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200,
9:02:50 AM: force: false
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/conversations/:id”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200,
9:02:50 AM: force: false
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/_next/data/JOLqHbHezIh6MvxXn2nmo/conversations/:id/messages/:messageId.json”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200,
9:02:50 AM: force: false
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: “/conversations/:id/messages/:messageId”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200,
9:02:50 AM: force: false
9:02:50 AM: },
9:02:50 AM: {
9:02:50 AM: from: "/
”,
9:02:50 AM: to: “/.netlify/functions/___netlify-handler”,
9:02:50 AM: status: 200
9:02:50 AM: }
9:02:50 AM: ].
9:02:50 AM: ​
9:02:50 AM: (@netlify/plugin-nextjs onBuild completed in 210ms)
9:02:50 AM: ​
9:02:50 AM: Functions bundling
9:02:50 AM: ────────────────────────────────────────────────────────────────
9:02:50 AM: ​
9:02:50 AM: Packaging Functions from .netlify/functions-internal directory:
9:02:50 AM: - ___netlify-handler/___netlify-handler.js
9:02:50 AM: - ___netlify-odb-handler/___netlify-odb-handler.js
9:02:50 AM: - _ipx/_ipx.js
9:02:50 AM: ​
9:03:32 AM: ​
9:03:32 AM: (Functions bundling completed in 42.3s)
9:03:32 AM: ​
9:03:32 AM: Edge Functions bundling
9:03:32 AM: ────────────────────────────────────────────────────────────────
9:03:32 AM: ​
9:03:32 AM: Packaging Edge Functions from .netlify/edge-functions directory:
9:03:32 AM: - next_middleware
9:03:45 AM: ​
9:03:45 AM: (Edge Functions bundling completed in 12.4s)
9:03:45 AM: ​
9:03:45 AM: @netlify/plugin-nextjs (onPostBuild event)
9:03:45 AM: ────────────────────────────────────────────────────────────────
9:03:45 AM: ​
9:03:45 AM: Next.js cache saved.
9:03:45 AM: :test_tube: Thank you for testing “appDir” support on Netlify. For known issues and to give feedback, visit Using the Next 13 `app` directory on Netlify · netlify/next-runtime · Discussion #1724 · GitHub
9:03:45 AM: ​
9:03:45 AM: (@netlify/plugin-nextjs onPostBuild completed in 283ms)
9:03:45 AM: ​
9:03:53 AM: (Netlify Build completed in 1m 26.7s)
9:03:58 AM: Section completed: building
9:04:18 AM: Finished processing build request in 2m35.303s

Thankx for your help

I realized that on my local machine the conversations route is getting invoked

image

Which is not the case on the deployed app after logging in

image

Next.js 13.3+ (in some cases even 13.3) is more or less unstable at the moment on Netlify. We’re working on improving better support, but due to limited time and resources, unfortunately we cannot check issues individually right now. Next 12 would most likely work fine, Next 13.1 should work to some extent too, can’t say about any versions after that.