When implementing a tenant aware auth instance using Firebase Admin SDK I cannot use the following method.
Code:
// defined elsewhere: locals.tenantAuth = getAuth().tenantManager().authForTenant(tenantId)
async createSession (locals) {
try {
const { idToken, expiresIn, tenantAuth } = locals
const decodedToken = await tenantAuth.verifyIdToken(idToken, true) // this works
// Only process if the user just signed in in the last 3 minutes
if (new Date().getTime() / 1000 - decodedToken.auth_time < 3 * 60) {
return await tenantAuth.createSessionCookie(idToken, { expiresIn }) // this breaks
} else {
throw new Error('Cannot create session, sign in information is too old')
}
} catch (error) {
console.log(error)
throw new Error(error)
}
}
Error:
FirebaseAuthError: This operation is not supported in a multi-tenant context.
errorInfo: {
code: 'auth/unsupported-tenant-operation',
message: 'This operation is not supported in a multi-tenant context.'
},
codePrefix: 'auth'
Version:
- Nodejs: 16.13.0
- Firebase Admin SDK: 10.0.0
Additional:
- Method works outside of tenantAware auth (using default project
getAuth()
) - Same error on v9
CodePudding user response:
This is already submitted as a feature request. You may check its status through this submitted feature request link.
You may want to check this Stack Overflow link as a workaround.