"pkcs8" must be PKCS#8 formatted string
andreaskienle opened this issue · comments
For me the login does not work on the deployed version. I see the following errors in the Vercel logs:
- [GET] [middleware: "src/middleware"] /api/login reason=EDGE_FUNCTION_INVOCATION_FAILED, status=500, user_error=true
- TypeError: "pkcs8" must be PKCS#8 formatted string
at (node_modules/jose/dist/browser/key/import.js:20:14)
…
On my local machine everything works fine.
Just to be on the safe side: I set FIREBASE_ADMIN_PRIVATE_KEY
on Vercel in the environment variables to
"-----BEGIN PRIVATE KEY-----\n<………>\n-----END PRIVATE KEY-----\n"
, i.e. including the quotation marks.
Ok, after some digging around I got it working: I used the starter app where the environment variable is read like this:
privateKey: process.env.FIREBASE_ADMIN_PRIVATE_KEY.replace(/\\n/g, "\n")!
I compared this to how next-firebase-auth does it and changed it to the following:
privateKey: JSON.parse(process.env.NEXT_PRIVATE_FIREBASE_ADMIN_PRIVATE_KEY).replace(/\\n/g, '\n')!
Locally (.env.local
), I had to add an additional pair of single quotes around the key:
FIREBASE_ADMIN_PRIVATE_KEY='"-----BEGIN PRIVATE KEY-----\n<………>\n-----END PRIVATE KEY-----\n"'
. (On Vercel, I had to remove the single quotes.)