From 1f85631f558e9579903b4276c22d44af2ca94ec3 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sun, 29 Oct 2023 15:39:46 +0100 Subject: [PATCH] namespacing --- README.md | 2 +- src/db/models/User.ts | 5 +++++ src/routes/auth/manage.ts | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cae692..6df09e1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Backend for movie-web - [ ] ratelimits (stored in redis) - [X] switch to pnpm - [X] catpcha support - - [ ] global namespacing (accounts are stored on a namespace) + - [X] global namespacing (accounts are stored on a namespace) - [ ] cleanup jobs - [ ] cleanup expired sessions - [ ] cleanup old metrics diff --git a/src/db/models/User.ts b/src/db/models/User.ts index 931e1bf..adad648 100644 --- a/src/db/models/User.ts +++ b/src/db/models/User.ts @@ -12,6 +12,9 @@ export class User { @PrimaryKey({ name: 'id', type: 'uuid' }) id: string = randomUUID(); + @Property({ name: 'namespace' }) + namespace!: string; + @Property({ type: 'date' }) createdAt: Date = new Date(); @@ -30,6 +33,7 @@ export class User { export interface UserDTO { id: string; + namespace: string; name: string; roles: string[]; createdAt: string; @@ -43,6 +47,7 @@ export interface UserDTO { export function formatUser(user: User): UserDTO { return { id: user.id, + namespace: user.namespace, name: user.name, roles: user.roles, createdAt: user.createdAt.toISOString(), diff --git a/src/routes/auth/manage.ts b/src/routes/auth/manage.ts index 7032219..a506a00 100644 --- a/src/routes/auth/manage.ts +++ b/src/routes/auth/manage.ts @@ -7,6 +7,7 @@ import { makeSession, makeSessionToken } from '@/services/session'; import { z } from 'zod'; const registerSchema = z.object({ + namespace: z.string().min(1), name: z.string().max(500).min(1), device: z.string().max(500).min(1), profile: z.object({ @@ -25,6 +26,7 @@ export const manageAuthRouter = makeRouter((app) => { await assertCaptcha(body.captchaToken); const user = new User(); + user.namespace = body.namespace; user.name = body.name; user.profile = body.profile;