feat(web): improve /auth pages (#1969)

* feat(web): improve /auth pages

* invalidate load functions after login

* handle login server errors more graceful

* add loading state to oauth button
This commit is contained in:
Michel Heusschen
2023-03-15 22:38:29 +01:00
committed by GitHub
parent 04955a4123
commit 87d84b922f
10 changed files with 299 additions and 276 deletions
+19 -1
View File
@@ -1,14 +1,32 @@
import { AppRoute } from '$lib/constants';
import { redirect } from '@sveltejs/kit';
import type { OAuthConfigResponseDto } from '@api';
import type { PageServerLoad } from './$types';
export const load = (async ({ locals: { api } }) => {
const { data } = await api.userApi.getUserCount(true);
if (data.userCount === 0) {
// Admin not registered
throw redirect(302, '/auth/register');
throw redirect(302, AppRoute.AUTH_REGISTER);
}
let authConfig: OAuthConfigResponseDto = {
passwordLoginEnabled: true,
enabled: false
};
try {
// TODO: Figure out how to get correct redirect URI server-side.
const { data } = await api.oauthApi.generateConfig({ redirectUri: '/' });
data.url = undefined;
authConfig = data;
} catch (err) {
console.error('[ERROR] login/+page.server.ts:', err);
}
return {
authConfig,
meta: {
title: 'Login'
}