chore: rewrite /login page for OAuth, write createUser for the database

This commit is contained in:
2023-01-10 20:07:25 +01:00
parent 2901a1f899
commit 9ae74fa649
9 changed files with 61 additions and 55 deletions
+7 -2
View File
@@ -2,7 +2,7 @@ import crypto from 'crypto'
import { readFile, writeFile, access, constants } from 'fs/promises'
import { MetadataProps as MetaProps, Problem, ProblemId, Solution, SolutionId, User } from '../../shared/model'
import { MetadataProps as MetaProps, Problem, ProblemId, Solution, SolutionId, User, UserId, UserRole } from '../../shared/model'
function once<T extends (...args: any) => any>(fn: T, message: string): T {
let flag = false
@@ -53,7 +53,7 @@ function createMutex(): Mutex {
return { lock }
}
type DatabaseConnection = {
export type DatabaseConnection = {
path: string
initialValue: Database
mu: Mutex
@@ -110,6 +110,11 @@ export const getUser: (db: DatabaseConnection, id: string) => Promise<User | nul
return state.users[id] ?? null
})
export const createUser: (db: DatabaseConnection, user: User) => Promise<void> = (db, user) =>
withDatabase(db, state => {
state.users[user.id] = user
})
//
// Problems
//