Error login using Metamask, error code A0003

I am using the demo code for the login using Metamask. It works fine in localhost, however when I deploy it to Vercel, it has the following error in console log

POST https://stratx.svb.ventures/api/auth/callback/moralis-auth 401 (Unauthorized)
(anonymous) @ _app-3510dc07ab7d8bd7.js:1
p @ _app-3510dc07ab7d8bd7.js:1
s.value @ _app-3510dc07ab7d8bd7.js:1
(anonymous) @ _app-3510dc07ab7d8bd7.js:1
t @ _app-3510dc07ab7d8bd7.js:1
s @ _app-3510dc07ab7d8bd7.js:1
Promise.then
t @ _app-3510dc07ab7d8bd7.js:1
s @ _app-3510dc07ab7d8bd7.js:1
Promise.then
t @ _app-3510dc07ab7d8bd7.js:1
s @ _app-3510dc07ab7d8bd7.js:1
(anonymous) @ _app-3510dc07ab7d8bd7.js:1
(anonymous) @ _app-3510dc07ab7d8bd7.js:1
D @ _app-3510dc07ab7d8bd7.js:1
t.signIn @ _app-3510dc07ab7d8bd7.js:1
n @ index-87a17aa56372c153.js:1
await in n
(anonymous) @ index-87a17aa56372c153.js:1
uI @ framework-2dad2a7bcc95afcf.js:1
oU @ framework-2dad2a7bcc95afcf.js:1
o @ framework-2dad2a7bcc95afcf.js:1
x @ framework-2dad2a7bcc95afcf.js:1
T @ framework-2dad2a7bcc95afcf.js:1

injection-tss.js?nonce=f3iojp8x4v8z4dlno75auhs25k8kfv0g9xdlom5wemc:1
TSS: Counted history being pushed
injection-tss.js?nonce=f3iojp8x4v8z4dlno75auhs25k8kfv0g9xdlom5wemc:1
TSS: Caught history
injection-tss.js?nonce=f3iojp8x4v8z4dlno75auhs25k8kfv0g9xdlom5wemc:1
TSS: Checking if repeated 500 times for interval 1000 against data: {lastTime: 1731762601171, lastCount: 1}

Check Vercel Logs, it show the error :

Moralis[nextjs]: Unknown error in MoralisNextAuthProvider authorize [A0003] apiKey is not set {
error: Error [Moralis SDK API Error]: [A0003] apiKey is not set
at OperationRequestBuilder.prepareHeaders (/var/task/node_modules/@moralisweb3/api-utils/lib/cjs/index.cjs:210:19)
at OperationResolver. (/var/task/node_modules/@moralisweb3/api-utils/lib/cjs/index.cjs:244:62)
at step (/var/task/node_modules/@moralisweb3/api-utils/lib/cjs/index.cjs:151:23)
at Object.next (/var/task/node_modules/@moralisweb3/api-utils/lib/cjs/index.cjs:132:53)
at (/var/task/node_modules/@moralisweb3/api-utils/lib/cjs/index.cjs:125:71)
at new Promise ()
at __awaiter (/var/task/node_modules/@moralisweb3/api-utils/lib/cjs/index.cjs:121:12)
at OperationResolver.fetch (/var/task/node_modules/@moralisweb3/api-utils/lib/cjs/index.cjs:231:50)
at Object. (/var/task/node_modules/@moralisweb3/next/lib/auth/MoralisNextAuthProvider.js:117:170)
at step (/var/task/node_modules/@moralisweb3/next/lib/auth/MoralisNextAuthProvider.js:44:23) {
isMoralisError: true,
code: ‘A0003’,
details: undefined,
constructor: [Function: MoralisError] { makeMessage: [Function (anonymous)] }
}
}

But I tested and confirm process.env.MORALIS_API_KEY show the correct API key without any issue.

Appreciated your help a lot.

Hi @LongPhan A possible reason is that the API keys are not set on vercel environment variables. Can you please verify if that is the case?

As mentioned, it was set properly. I can recall it using process.env.MORALIS_API_KEY and it show correct API Key

But as per the error in code, the your code is not able to read the API key. Maybe try building the project again in vercel