创建 Firebase 用户并快速添加声明的脚本?
A script to create Firebase user and add claims quickly?
我想知道是否有人手头有脚本可以获取管理员 JSON 配置文件的路径并创建具有自定义声明的用户?
我从来没有写过剧本,但我猜是这样的
import FirebaseAdmin
import "./config.json"
//maybe gets the userID from the console?
createUser() {
...create user and attach the claims
}
这是一个 Node.js 脚本,它将创建两个用户并为他们分配一个 role
声明。您可以根据需要添加任意数量的用户,只需 copy/paste 并调整 const p1
块并将 p<X>
承诺添加到数组中。
你 运行 它通过调用 node thenameofthescriptfile.js
#!/usr/bin/node
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert("xyz.json")
});
const p1 = admin.auth()
.createUser({
email: '...',
password: '....',
displayName: '....'
})
.then((userRecord) => {
return admin.auth().setCustomUserClaims(userRecord.uid, { role: "..." })
})
.catch((error) => {
console.log('Error creating new user:', error);
});
const p2 = admin.auth()
.createUser({
email: '...',
password: '....',
displayName: '....'
})
.then((userRecord) => {
return admin.auth().setCustomUserClaims(userRecord.uid, { role: "..." })
})
.catch((error) => {
console.log('Error creating new user:', error);
});
Promise.all([p1, p2]);
我想知道是否有人手头有脚本可以获取管理员 JSON 配置文件的路径并创建具有自定义声明的用户?
我从来没有写过剧本,但我猜是这样的
import FirebaseAdmin
import "./config.json"
//maybe gets the userID from the console?
createUser() {
...create user and attach the claims
}
这是一个 Node.js 脚本,它将创建两个用户并为他们分配一个 role
声明。您可以根据需要添加任意数量的用户,只需 copy/paste 并调整 const p1
块并将 p<X>
承诺添加到数组中。
你 运行 它通过调用 node thenameofthescriptfile.js
#!/usr/bin/node
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert("xyz.json")
});
const p1 = admin.auth()
.createUser({
email: '...',
password: '....',
displayName: '....'
})
.then((userRecord) => {
return admin.auth().setCustomUserClaims(userRecord.uid, { role: "..." })
})
.catch((error) => {
console.log('Error creating new user:', error);
});
const p2 = admin.auth()
.createUser({
email: '...',
password: '....',
displayName: '....'
})
.then((userRecord) => {
return admin.auth().setCustomUserClaims(userRecord.uid, { role: "..." })
})
.catch((error) => {
console.log('Error creating new user:', error);
});
Promise.all([p1, p2]);