Skip to content

Commit

Permalink
feat(auth): added creat custom token utility
Browse files Browse the repository at this point in the history
  • Loading branch information
flauc committed Feb 22, 2024
1 parent ea6cf2d commit 964e79c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ async function init() {
.action(auth.getUser)
);

commands.auth.addCommand(
new Command('create-custom-token')
.alias('cct')
.description('Creates a custom auth token')
.addArgument(new Argument('<uid>', `UID for the token it doesn't have to be a real one.`))
.addArgument(new Argument('[customClames]', `Arbitrary custom clames to add to the tokne.`))
.action(auth.createCustomToken)
)

/**
* FIRESTORE
*/
Expand Down
11 changes: 11 additions & 0 deletions src/commands/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ async function getUser(identifier, output) {
}
}

async function createCustomToken(uid, customClaims) {
try {
initializeFirebase();
const token = await admin.auth().createCustomToken(uid, customClaims ? JSON.parse(customClaims) : {});
return successMessage(`Generated token: ${token}`);
} catch (error) {
errorMessage(`Something went wrong!\n\n${error}`);
}
}

module.exports = {
createUser,
updateClaims,
Expand All @@ -226,4 +236,5 @@ module.exports = {
removeUsers,
listUsers,
getUser,
createCustomToken
}

0 comments on commit 964e79c

Please sign in to comment.