mirror of
https://github.com/kevin-DL/commander_league_web.git
synced 2026-01-14 03:04:51 +00:00
Initial commit from Create Next App
This commit is contained in:
24
utils/auth/firebaseAdmin.js
Normal file
24
utils/auth/firebaseAdmin.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import * as admin from 'firebase-admin'
|
||||
|
||||
export const verifyIdToken = (token) => {
|
||||
const firebasePrivateKey = process.env.FIREBASE_PRIVATE_KEY
|
||||
|
||||
if (!admin.apps.length) {
|
||||
admin.initializeApp({
|
||||
credential: admin.credential.cert({
|
||||
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
|
||||
clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
|
||||
// https://stackoverflow.com/a/41044630/1332513
|
||||
privateKey: firebasePrivateKey.replace(/\\n/g, '\n'),
|
||||
}),
|
||||
databaseURL: process.env.NEXT_PUBLIC_FIREBASE_DATABASE_URL,
|
||||
})
|
||||
}
|
||||
|
||||
return admin
|
||||
.auth()
|
||||
.verifyIdToken(token)
|
||||
.catch((error) => {
|
||||
throw error
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user