I am trying to deploy my next app to vercel. I am using next-auth for authentication with credentials and an api that returns a JWT. On localhost it works ok, but when I put it on vercel, and try to login, nothing happens. However when I view the logs in the project's dashboard functions, there's an error:
[POST] /api/auth/callback/credentials
03:32:18:58
2021-12-21T00:32:19.071Z 410db3c3-d841-45d1-8df2-0cdbb4aa8793 ERROR TypeError: "ikm"" must be an instance of Uint8Array or a string
at normalizeUint8Array (/var/task/node_modules/@panva/hkdf/dist/node/cjs/index.js:20:15)
at normalizeIkm (/var/task/node_modules/@panva/hkdf/dist/node/cjs/index.js:24:17)
at hkdf (/var/task/node_modules/@panva/hkdf/dist/node/cjs/index.js:47:60)
at getDerivedEncryptionKey (/var/task/node_modules/next-auth/jwt/index.js:99:34)
at Object.encode (/var/task/node_modules/next-auth/jwt/index.js:45:34)
at Object.callback (/var/task/node_modules/next-auth/core/routes/callback.js:457:37)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async NextAuthHandler (/var/task/node_modules/next-auth/core/index.js:197:28)
at async NextAuthNextHandler (/var/task/node_modules/next-auth/next/index.js:40:7)
at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils.js:101:9)
2021-12-21T00:32:19.071Z 410db3c3-d841-45d1-8df2-0cdbb4aa8793 ERROR TypeError: "ikm"" must be an instance of Uint8Array or a string
at normalizeUint8Array (/var/task/node_modules/@panva/hkdf/dist/node/cjs/index.js:20:15)
at normalizeIkm (/var/task/node_modules/@panva/hkdf/dist/node/cjs/index.js:24:17)
at hkdf (/var/task/node_modules/@panva/hkdf/dist/node/cjs/index.js:47:60)
at getDerivedEncryptionKey (/var/task/node_modules/next-auth/jwt/index.js:99:34)
at Object.encode (/var/task/node_modules/next-auth/jwt/index.js:45:34)
at Object.callback (/var/task/node_modules/next-auth/core/routes/callback.js:457:37)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async NextAuthHandler (/var/task/node_modules/next-auth/core/index.js:197:28)
at async NextAuthNextHandler (/var/task/node_modules/next-auth/next/index.js:40:7)
at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils.js:101:9)
RequestId: 410db3c3-d841-45d1-8df2-0cdbb4aa8793 Error: Runtime exited with error: exit status 1
Runtime.ExitError
Additional info:
The SignIn()
function looks like this:
signIn("credentials", {
email: values.name,
password: values.password,
redirect: false,
callbackUrl: `/app`
})
.then((data) => console.log("loginpagethen", data))
.catch((error) => console.log("loginpagecatch", error));
I think the problem occurs somewhere in the jwt callback
function because authorize
returns a user(with all the data, including jwt from server). Also if I console.log the user in the jwt callback
function,I can actually see the user object. However the session isn't present.
async jwt({ token, user, account, profile, isNewUser }) {
if (user) {
console.log("user", user); //user is there
token.accessToken = user.token;
}
return token;
},
async session(session, token) {
console.log("session", session); //session is not there
return session;
},
};
P.S. I have added environment variables.
Any idea on how I can get my app to behave on vercel?