Hi all,
I’m using Nextjs 14.2.5 with Nextjs Runtime v5.
I have a Nextjs redirect() that causes an error when it is invoked in the netlify generated serverless function. I call the checkAuth() at the top of my layout.ts file and this function calls the redirect like so. Any help on how to debug this would be greatly appreciated. Thank you!
import { redirect } from "next/navigation";
export const checkAuth = async () => {
const session = await getPageSession();
if (!session) redirect("/sign-in");
};
Here the serverless function log.
Sep 21, 09:12:10 PM: INIT_START Runtime Version: nodejs:18.v41 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:04bd440b3352c7bb54e276ef3b22f969cd3994745c14b37929e1095c726a855c
Sep 21, 09:12:10 PM: INIT_START Runtime Version: nodejs:18.v41 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:04bd440b3352c7bb54e276ef3b22f969cd3994745c14b37929e1095c726a855c
Sep 21, 09:12:10 PM: INIT_START Runtime Version: nodejs:18.v41 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:04bd440b3352c7bb54e276ef3b22f969cd3994745c14b37929e1095c726a855c
Sep 21, 09:12:10 PM: INIT_START Runtime Version: nodejs:18.v41 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:04bd440b3352c7bb54e276ef3b22f969cd3994745c14b37929e1095c726a855c
Sep 21, 09:12:11 PM: INFO import next server: 319.999ms
Sep 21, 09:12:11 PM: INFO import next server: 310.632ms
Sep 21, 09:12:11 PM: INFO import next server: 312.645ms
Sep 21, 09:12:11 PM: INFO import next server: 357.796ms
Sep 21, 09:12:14 PM: 72e72428 Duration: 2745.09 ms Memory Usage: 0 MB
Sep 21, 09:12:14 PM: 8555c23d Duration: 2734.21 ms Memory Usage: 0 MB
Sep 21, 09:12:14 PM: f4a79b40 Duration: 2881.81 ms Memory Usage: 0 MB
Sep 21, 09:12:14 PM: ee71dba7 Duration: 2888.71 ms Memory Usage: 0 MB
Sep 21, 09:12:14 PM: 4bdf511a Duration: 83.52 ms Memory Usage: 0 MB
Sep 21, 09:12:14 PM: 2d96dee7 Duration: 100.31 ms Memory Usage: 0 MB
Sep 21, 09:12:14 PM: 182ea37f Duration: 76.54 ms Memory Usage: 0 MB
Sep 21, 09:12:14 PM: 1556343d Duration: 109.71 ms Memory Usage: 0 MB
Sep 21, 09:12:38 PM: 5d37e0ce Duration: 23.61 ms Memory Usage: 0 MB
Sep 21, 09:12:39 PM: 69d3185d Duration: 105.36 ms Memory Usage: 0 MB
Sep 21, 09:12:41 PM: bffc6531 Duration: 1744.04 ms Memory Usage: 0 MB
Sep 21, 09:12:41 PM: eaed92c5 Duration: 90.47 ms Memory Usage: 0 MB
Sep 21, 09:12:41 PM: 5d2b3594 Duration: 32.39 ms Memory Usage: 0 MB
Sep 21, 09:12:41 PM: 2e49b11e Duration: 22.93 ms Memory Usage: 0 MB
Sep 21, 09:12:42 PM: 91b8d6c8 Duration: 28.04 ms Memory Usage: 0 MB
Sep 21, 09:12:42 PM: 38d3db7a Duration: 19.93 ms Memory Usage: 0 MB
Sep 21, 09:12:42 PM: 307b7522 Duration: 47.56 ms Memory Usage: 0 MB
Sep 21, 09:12:43 PM: 5f04784a ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: NEXT_REDIRECT","reason":{"errorType":"Error","errorMessage":"NEXT_REDIRECT","digest":"NEXT_REDIRECT;replace;/sign-in;307;","mutableCookies":{"_parsed":{},"_headers":{}},"stack":["Error: NEXT_REDIRECT"," at a (/var/task/.next/server/chunks/2583.js:1:22823)"," at s (/var/task/.next/server/chunks/2583.js:1:23038)"," at n (/var/task/.next/server/chunks/1581.js:1:11563)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: NEXT_REDIRECT"," at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)"," at process.emit (node:events:529:35)"," at emit (node:internal/process/promises:149:20)"," at processPromiseRejections (node:internal/process/promises:283:27)"," at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}
Sep 21, 09:13:13 PM: [ERROR] [1726945993865] LAMBDA_RUNTIME Failed to post handler success response. Http response code: 403.
Sep 21, 09:13:13 PM: 5f04784a ERROR Task timed out after 30.03 seconds
Sep 21, 09:13:13 PM: 5f04784a Duration: 30026.75 ms Memory Usage: 0 MB
Sep 21, 09:14:37 PM: INFO import next server: 520.463ms
Sep 21, 09:14:39 PM: 4eaee78d Duration: 3878.09 ms Memory Usage: 0 MB
Sep 21, 09:19:31 PM: 562cb4d6 Duration: 1605.58 ms Memory Usage: 0 MB