Next Auth problem in Vercel

I'm currently deploying my app in Vercel but it won't work because of the following error:
TypeError: "ikm"" must be an instance of Uint8Array or a string
at (node_modules/@panva/hkdf/dist/web/index.js:17:0)
at (node_modules/@panva/hkdf/dist/web/index.js:21:0)
at (node_modules/@panva/hkdf/dist/web/index.js:44:17)
at (node_modules/next-auth/jwt/index.js:114:0)
at (node_modules/next-auth/jwt/index.js:61:0)
at (src/middleware.ts:23:28)
at (node_modules/next/dist/esm/server/web/adapter.js:97:0)
at ([native code])
TypeError: "ikm"" must be an instance of Uint8Array or a string
at (node_modules/@panva/hkdf/dist/web/index.js:17:0)
at (node_modules/@panva/hkdf/dist/web/index.js:21:0)
at (node_modules/@panva/hkdf/dist/web/index.js:44:17)
at (node_modules/next-auth/jwt/index.js:114:0)
at (node_modules/next-auth/jwt/index.js:61:0)
at (src/middleware.ts:23:28)
at (node_modules/next/dist/esm/server/web/adapter.js:97:0)
at ([native code])
This is the block of code in middleware.ts that the stack trace refers to:
const user = await decode({
token: token.value,
secret: process.env.NEXTAUTH_SECRET!,
});
const user = await decode({
token: token.value,
secret: process.env.NEXTAUTH_SECRET!,
});
Googling it looks like NEXTAUTH_SECRET is not set up in Vercel, but it is (as the image shows). Tips?
7 Replies
Finn
Finn2y ago
whats the type signature of decode?
Victor Costelini
Victor CosteliniOP2y ago
export interface JWTDecodeParams {
/** The NextAuth.js issued JWT to be decoded */
token?: string;
/** The secret used to decode the NextAuth.js issued JWT. */
secret: string | Buffer;
}
export interface JWTDecodeParams {
/** The NextAuth.js issued JWT to be decoded */
token?: string;
/** The secret used to decode the NextAuth.js issued JWT. */
secret: string | Buffer;
}
Finn
Finn2y ago
i guess just pass the secret in as a buffer
Victor Costelini
Victor CosteliniOP2y ago
export declare function decode(params: JWTDecodeParams): Promise<JWT | null>;
export declare function decode(params: JWTDecodeParams): Promise<JWT | null>;
Finn
Finn2y ago
are you use you have set the env var?
Victor Costelini
Victor CosteliniOP2y ago
I tried hardcoding it and it still won't work. Trying the Buffer now. HOLY FUCK IT WORKED I was getting desperate by now. This solved the issue:
const user = await decode({
token: authToken,
secret: Buffer.from(process.env.NEXTAUTH_SECRET!),
});
const user = await decode({
token: authToken,
secret: Buffer.from(process.env.NEXTAUTH_SECRET!),
});
Finn
Finn2y ago
Want results from more Discord servers?
Add your server