overleaf/services/web/scripts/create_oauth_personal_access_token.mjs
Liangjun Song 26f3f3e2e2 Merge pull request #21097 from overleaf/ls-scripts-to-esm-1
Migrate scripts folder to esm 1/x

GitOrigin-RevId: 4a4bc9a161f144fdb40ce3f2a0a9313b36c6df81
2024-10-21 08:04:42 +00:00

33 lines
890 B
JavaScript

// Script to create a Personal Access Token for a given user
// Example:
// node scripts/create_oauth_personal_access_token.mjs --user-id=643e5b240dc50c83b5bf1127
import parseArgs from 'minimist'
import { waitForDb } from '../app/src/infrastructure/mongodb.js'
import OAuthPersonalAccessTokenManager from '../modules/oauth2-server/app/src/OAuthPersonalAccessTokenManager.js'
const argv = parseArgs(process.argv.slice(2), {
string: ['user-id'],
})
const userId = argv['user-id']
if (!userId) {
console.error('Missing --user-id argument')
process.exit(1)
}
async function createPersonalAccessToken() {
await waitForDb()
const accessToken = await OAuthPersonalAccessTokenManager.createToken(userId)
console.log('Personal Access Token: ' + accessToken)
}
try {
await createPersonalAccessToken()
process.exit()
} catch (error) {
console.error(error)
process.exit(1)
}