Hi, I'm hoping I could get some help with this cloud function code to keep the admin user signed in after he creates an account so he isn't logged out automatically. It deploys successfully but I still keep getting logged out after an account is created. Can anyone help with an alternative or let me know what is wrong with this one. Thanks in advance.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
exports.createUserAndPreserveSession = functions.auth.user().onCreate(async (user) => {
try {
// Set a custom claim to flag the user for special treatment
await admin.auth().setCustomUserClaims(user.uid, { preserveSession: true });
console.log(`User ${user.uid} flagged for session preservation.`);
return null;
} catch (error) {
console.error(`Error setting custom claims for user: ${error}`);
}
});