-
Notifications
You must be signed in to change notification settings - Fork 43
How to access admin.auth()? #34
Comments
Would also like to know, what the way to go is, when needing auth data. |
I have the same need. For me, the following error occurs:
What I did:
What to do to get the firebase-admin functions working with Fireway? By the way, I came across this package (looks like a fireway fork?) that seems to support |
I'd accept a PR for an I'd rather expose the result of |
I'm not sure I understand this. FWIW, here's a snapshot of the migration script that produces the error I shared above: // v0.0.2_set_custom_claims.js
// helpers.js
|
I want to reduce surface area, because in my experience, more surface area is more that can break. If you need
If it runs against localhost, but not remotely, continue to do what you're doing now ( |
It'd be nice to see how to use the
It doesn't work on localhost right now (the error I shared is from localhost - To rephrase the issue: I don't know how else on localhost (besides setting the env variable) to tell fireway that I am using the Firebase emulator and that I don't have a real project ID or other credentials since I'm using the emulator. Thanks for your patience, I am new to JS/NoSQL :) |
It doesn't work today, but ideally your migration file could look something like: module.exports = async ({ firestore, auth }) => {
// your migration logic
};
Ah. An
No worries! Happy to help. |
It normally works for me but it's not working for me in this particular use case (i.e., when using the firebase admin SDK's modules - I have also tried running the script against a remote database by providing the |
const clearClaims = async (auth, authUser) => {
if (authUser.customClaims) {
return await auth.setCustomUserClaims(authUser.uid, null);
}
};
const updateClaims = async (auth, authUser, changes) => {
const newCustomClaims = { ...authUser.customClaims, ...changes };
return await auth.setCustomUserClaims(authUser.uid, newCustomClaims);
};
module.exports.migrate = async ({ firestore, app }) => {
const auth = app.auth();
const usersSnapshot = await firestore.collection("users").get();
usersSnapshot.forEach(async (snapshot) => {
const userId = snapshot.id;
try {
const authUser = await auth.getUser(userId);
// await clearClaims(auth, authUser);
// console.log(authUser.customClaims);
await updateClaims(auth, authUser, { admin: true });
} catch (error) {
// console.log(error, userId);
}
});
}; |
Hi. In my case, the fireway
I end up configuring my env using these two variables:
Local migration using 'app.auth' works properly with the emulator now ! |
Is it even possible to access the admin object from the migration script?
I want to change some filed names inside
customUserClaims
, so I thought it would be nice to create a migration for that. But for doing that I would need toaccess admin.auth().listUsers()
and then runsetCustomUserClaims()
for each individual user.I've added
const admin = require("firebase-admin");
before the script, which amazingly worked, but that feels like a workaround and not a proper solution.I would suggest adding
admin
object toMigrateOptions
The text was updated successfully, but these errors were encountered: