chore: rewrite /login page for OAuth, write createUser for the database
This commit is contained in:
@@ -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
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user