namespacing

This commit is contained in:
mrjvs
2023-10-29 15:39:46 +01:00
parent e9f8845506
commit 1f85631f55
3 changed files with 8 additions and 1 deletions

View File

@@ -27,7 +27,7 @@ Backend for movie-web
- [ ] ratelimits (stored in redis) - [ ] ratelimits (stored in redis)
- [X] switch to pnpm - [X] switch to pnpm
- [X] catpcha support - [X] catpcha support
- [ ] global namespacing (accounts are stored on a namespace) - [X] global namespacing (accounts are stored on a namespace)
- [ ] cleanup jobs - [ ] cleanup jobs
- [ ] cleanup expired sessions - [ ] cleanup expired sessions
- [ ] cleanup old metrics - [ ] cleanup old metrics

View File

@@ -12,6 +12,9 @@ export class User {
@PrimaryKey({ name: 'id', type: 'uuid' }) @PrimaryKey({ name: 'id', type: 'uuid' })
id: string = randomUUID(); id: string = randomUUID();
@Property({ name: 'namespace' })
namespace!: string;
@Property({ type: 'date' }) @Property({ type: 'date' })
createdAt: Date = new Date(); createdAt: Date = new Date();
@@ -30,6 +33,7 @@ export class User {
export interface UserDTO { export interface UserDTO {
id: string; id: string;
namespace: string;
name: string; name: string;
roles: string[]; roles: string[];
createdAt: string; createdAt: string;
@@ -43,6 +47,7 @@ export interface UserDTO {
export function formatUser(user: User): UserDTO { export function formatUser(user: User): UserDTO {
return { return {
id: user.id, id: user.id,
namespace: user.namespace,
name: user.name, name: user.name,
roles: user.roles, roles: user.roles,
createdAt: user.createdAt.toISOString(), createdAt: user.createdAt.toISOString(),

View File

@@ -7,6 +7,7 @@ import { makeSession, makeSessionToken } from '@/services/session';
import { z } from 'zod'; import { z } from 'zod';
const registerSchema = z.object({ const registerSchema = z.object({
namespace: z.string().min(1),
name: z.string().max(500).min(1), name: z.string().max(500).min(1),
device: z.string().max(500).min(1), device: z.string().max(500).min(1),
profile: z.object({ profile: z.object({
@@ -25,6 +26,7 @@ export const manageAuthRouter = makeRouter((app) => {
await assertCaptcha(body.captchaToken); await assertCaptcha(body.captchaToken);
const user = new User(); const user = new User();
user.namespace = body.namespace;
user.name = body.name; user.name = body.name;
user.profile = body.profile; user.profile = body.profile;