Skip to content

Commit

Permalink
feat: better account creation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
rutmanz committed Aug 30, 2024
1 parent 924b6a7 commit 1a959ff
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
9 changes: 9 additions & 0 deletions MAINTAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
## Adding Members

Visit `/admin/members/` and enter data in the bottom row. Slack IDs will automatically populate by the email
Alternatively use the onboarding button on the app home

## Creating Accounts

To create an account,
Role should be "read" "write" or "admin"
```
npm run createaccount youruser yourpassword role
```

## Adjusting Seasons

Expand Down
41 changes: 41 additions & 0 deletions dev/create_account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { PrismaClient } from '@prisma/client'
import { createUser } from '~lib/auth'
import logger from '~lib/logger'

const prisma = new PrismaClient()




async function main() {
await createUser(process.argv[2].trim(), process.argv[3].trim(), level[0], level[1])
}

const levels:Record<string, [boolean, boolean]> = {
"admin": [true, true],
"write": [true, false],
"read": [false, false]
}
console.log("-------")
if (process.argv.length < 5 || process.argv[2].length < 2 || process.argv[3].length<2 || process.argv[4].length < 2) {
console.log(process.argv)
console.warn("!Missing arguments")
process.exit(1)
}
const level = levels[process.argv[4].trim()]

if (levels[process.argv[4]] == null) {
console.log(process.argv)
console.warn("Invalid level")
process.exit(1)
}

await main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
logger.error(e)
await prisma.$disconnect()
process.exit(1)
})
19 changes: 0 additions & 19 deletions dev/seed_accounts.ts

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"lint:style": "prettier --check .",
"lint:code": "eslint . -c eslint.config.js",
"lint": "npm-run-all -l -c --parallel lint:**",
"format": "prettier --write ."
"format": "prettier --write .",
"createaccount": "tsx dev/create_account.ts $1 $2 $3"
},
"dependencies": {
"@googleapis/sheets": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function createUser(id: string, password: string, write_access: boo
password: hashedPassword,
write_access,
admin_access,
api_key: crypto.randomBytes(20).toString('hex')
api_key: crypto.randomBytes(18).toString('hex')
}
})
}
Expand Down

0 comments on commit 1a959ff

Please sign in to comment.