feat(oauth2/db): reworked oauth2 database footprint

- Removed `auth` table and merged its information inside the `user`
  table
- Changed around some field names in the database
- Changed Create*User functions to not be using overload but different
  functions
This commit is contained in:
Maieul BOYER 2025-11-13 16:00:05 +01:00 committed by Maix0
parent 34249bf68d
commit 5a905a1239
10 changed files with 90 additions and 142 deletions

View file

@ -31,15 +31,7 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
const adjective = getRandomFromList(fastify.words.adjectives);
const noun = getRandomFromList(fastify.words.nouns);
const user = await this.db.createUser(
// no login_name => can't login
null,
`${adjective} ${noun}`,
// no password
undefined,
// is a guest
true,
);
const user = await this.db.createGuestUser(`${adjective} ${noun}`);
if (isNullish(user)) {
return res.makeResponse(500, 'failed', 'guestLogin.failed.generic.unknown');
}

View file

@ -30,9 +30,9 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
const result = await creq.getCode();
const userinfo = await provider.getUserInfo(result);
let u = this.db.getUserFromProviderUser(provider.display_name, userinfo.unique_id);
let u = this.db.getOauth2User(provider.display_name, userinfo.unique_id);
if (isNullish(u)) {
u = await this.db.createUserWithProvider(provider.display_name, userinfo.unique_id, userinfo.name);
u = await this.db.createOauth2User(userinfo.name, provider.display_name, userinfo.unique_id);
}
if (isNullish(u)) {
return res.code(500).send('failed to fetch or create user...');
@ -40,7 +40,7 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
const token = this.signJwt('auth', u.id);
return res.setCookie('token', token, { path: '/' }).redirect('/');
return res.setCookie('token', token, { path: '/' }).redirect('/app/');
},
);
};

View file

@ -47,7 +47,7 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
// password is good too !
if (this.db.getUserFromLoginName(name) !== undefined) { return res.makeResponse(400, 'failed', 'signin.failed.username.existing'); }
const u = await this.db.createUser(name, name, password, false);
const u = await this.db.createUser(name, name, password);
if (isNullish(u)) { return res.makeResponse(500, 'failed', 'signin.failed.generic'); }
// every check has been passed, they are now logged in, using this token to say who they are...