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:
@@ -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'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user