fix(shared/auth/icon): Fixed lots of small things

Icons: Fixed docker-compose to force JWT_SECRET for now
Auth: Fixed Guest Login to actually work
Auth: Added `Login as Guest` in the login_demo page
Shared: Fixed db/user + uuid modules
This commit is contained in:
Maieul BOYER 2025-10-08 17:24:46 +02:00 committed by Maix0
parent 5306ccfc60
commit 2074f8d8f1
6 changed files with 51 additions and 11 deletions

View file

@ -20,6 +20,7 @@
<br />
<br />
<button id="b-login">Login</button>
<button id="b-login-guest">Login as Guest</button>
<br />
<button id="b-logout">Logout</button>
<br />

View file

@ -11,6 +11,7 @@ const iOtp = document.querySelector('#i-otp');
const bOtpSend = document.querySelector('#b-otpSend');
const bLogin = document.querySelector('#b-login');
const bLoginGuest = document.querySelector('#b-login-guest');
const bLogout = document.querySelector('#b-logout');
const bSignin = document.querySelector('#b-signin');
const bWhoami = document.querySelector('#b-whoami');
@ -27,6 +28,16 @@ function setResponse(obj) {
}
let otpToken = null;
bLoginGuest.addEventListener('click', async () => {
const res = await fetch('/api/auth/guest', { method: 'POST' });
const json = await res.json();
setResponse(json);
if (json.kind === 'success') {
if (json?.payload?.token) {document.cookie = `token=${json?.payload?.token}`;}
}
});
bOtpSend.addEventListener('click', async () => {
const res = await fetch('/api/auth/otp', { method: 'POST', body: JSON.stringify({ code: iOtp.value, token: otpToken }), headers });
const json = await res.json();

View file

@ -4,8 +4,8 @@ import { Static, Type } from '@sinclair/typebox';
import { typeResponse, makeResponse, isNullish } from '@shared/utils';
export const GuestLoginRes = Type.Union([
typeResponse('failed', 'login.failed.generic'),
typeResponse('success', 'login.success', {
typeResponse('failed', ['guestLogin.failed.generic.unknown', 'guestLogin.failed.generic.error']),
typeResponse('success', 'guestLogin.success', {
token: Type.String({
description: 'JWT that represent a logged in user',
}),
@ -38,14 +38,15 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
true,
);
if (isNullish(user)) {
return makeResponse('failed', 'login.failed.generic');
return makeResponse('failed', 'guestLogin.failed.generic.unknown');
}
return makeResponse('success', 'login.success', {
token: this.signJwt('auth', user.id),
return makeResponse('success', 'guestLogin.success', {
token: this.signJwt('auth', user.id.toString()),
});
}
catch {
return makeResponse('failed', 'login.failed.generic');
catch (e: unknown) {
fastify.log.error(e);
return makeResponse('failed', 'guestLogin.failed.generic.error');
}
},
);