feat(auth/user): Finished User Rework to handle Guest
- Split userinfo APIs to their own service (`user`) - Added user service to nginx and docker-compose - Cleaned up package.json across the project to remove useless depedencies - Added word list for Guest username generation (source in file itself) - Reworked internal of `user` DB to not have a difference between "raw" id and normal ID (UUID)
This commit is contained in:
parent
7d0f5c11d6
commit
1cbd778131
24 changed files with 4273 additions and 46 deletions
|
|
@ -100,7 +100,7 @@ export const authPlugin = fp<FastifyPluginAsync>(async (fastify, _opts) => {
|
|||
JSON.stringify(makeResponse('notLoggedIn', 'auth.invalidKind')),
|
||||
);
|
||||
}
|
||||
const user = this.db.getUserFromName(tok.who);
|
||||
const user = this.db.getUser(tok.who);
|
||||
if (isNullish(user)) {
|
||||
return res
|
||||
.clearCookie('token')
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@ import * as bcrypt from 'bcrypt';
|
|||
export interface IUserDb extends Database {
|
||||
getUser(id: UserId): User | undefined,
|
||||
getUserFromName(name: string): User | undefined,
|
||||
getUserFromRawId(id: number): User | undefined,
|
||||
getUser(id: string): User | undefined,
|
||||
getUserOtpSecret(id: UserId): string | undefined,
|
||||
createUser(name: string, password: string | undefined, guest: boolean): Promise<User | undefined>,
|
||||
createUser(name: string, password: string | undefined): Promise<User | undefined>,
|
||||
setUserPassword(id: UserId, password: string | undefined): Promise<User | undefined>,
|
||||
ensureUserOtpSecret(id: UserId): string | undefined,
|
||||
|
|
@ -17,17 +18,6 @@ export interface IUserDb extends Database {
|
|||
};
|
||||
|
||||
export const UserImpl: Omit<IUserDb, keyof Database> = {
|
||||
/**
|
||||
* Get a user from an [UserId]
|
||||
*
|
||||
* @param id the userid to fetch
|
||||
*
|
||||
* @returns The user if it exists, undefined otherwise
|
||||
*/
|
||||
getUser(this: IUserDb, id: UserId): User | undefined {
|
||||
return this.getUserFromRawId(id);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a user from a username [string]
|
||||
*
|
||||
|
|
@ -50,7 +40,7 @@ export const UserImpl: Omit<IUserDb, keyof Database> = {
|
|||
*
|
||||
* @returns The user if it exists, undefined otherwise
|
||||
*/
|
||||
getUserFromRawId(this: IUserDb, id: number): User | undefined {
|
||||
getUser(this: IUserDb, id: string): User | undefined {
|
||||
return userFromRow(
|
||||
this.prepare('SELECT * FROM user WHERE id = @id LIMIT 1').get({
|
||||
id,
|
||||
|
|
@ -113,7 +103,7 @@ export const UserImpl: Omit<IUserDb, keyof Database> = {
|
|||
},
|
||||
};
|
||||
|
||||
export type UserId = number & { readonly __brand: unique symbol };
|
||||
export type UserId = UUID;
|
||||
|
||||
export type User = {
|
||||
readonly id: UserId;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue