ui: auth: improve auth form and invite page
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
parent
230fcf79df
commit
bb80776776
28
src/lib/components/app/auth-form/auth-button.svelte
Normal file
28
src/lib/components/app/auth-form/auth-button.svelte
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { LucideLoaderCircle } from '@lucide/svelte';
|
||||||
|
import { Button } from '$lib/components/ui/button';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
providerName: string;
|
||||||
|
displayName: string;
|
||||||
|
iconSrc: string;
|
||||||
|
inviteToken?: string;
|
||||||
|
}
|
||||||
|
let { providerName, displayName, inviteToken, iconSrc }: Props = $props();
|
||||||
|
|
||||||
|
let submitted = $state(false);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form method="get" onsubmit={() => (submitted = true)} action="/auth/{providerName}">
|
||||||
|
{#if inviteToken}
|
||||||
|
<input type="hidden" value={inviteToken} name="invite" />
|
||||||
|
{/if}
|
||||||
|
<Button type="submit" disabled={submitted}>
|
||||||
|
{#if submitted}
|
||||||
|
<LucideLoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
||||||
|
{:else}
|
||||||
|
<img class="mr-2 h-4 w-4" alt="{displayName} Logo" src={iconSrc} />
|
||||||
|
{/if}
|
||||||
|
Sign {inviteToken ? 'up' : 'in'} with {displayName}
|
||||||
|
</Button>
|
||||||
|
</form>
|
@ -1,54 +1,26 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { LucideLoaderCircle } from '@lucide/svelte';
|
|
||||||
import { Button } from '$lib/components/ui/button';
|
|
||||||
import { cn } from '$lib/utils.js';
|
import { cn } from '$lib/utils.js';
|
||||||
import googleIcon from '$lib/assets/google.svg';
|
import googleIcon from '$lib/assets/google.svg';
|
||||||
import { enabledAuthProviders } from '$lib/auth';
|
import { enabledAuthProviders } from '$lib/auth';
|
||||||
|
import AuthButton from './auth-button.svelte';
|
||||||
|
|
||||||
let { inviteToken, class: className, ...rest }: {
|
interface Props {
|
||||||
inviteToken?: string;
|
inviteToken?: string;
|
||||||
class?: string;
|
class?: string;
|
||||||
rest?: { [p: string]: unknown }
|
}
|
||||||
} = $props();
|
let { inviteToken, class: className }: Props = $props();
|
||||||
|
|
||||||
let submitted = $state(false);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class={cn('flex gap-6', className)} {...rest}>
|
<div class={cn('flex gap-6', className)}>
|
||||||
{#if enabledAuthProviders.authentik }
|
{#if enabledAuthProviders.authentik}
|
||||||
<form method="get" onsubmit={() => submitted = true}
|
<AuthButton
|
||||||
action="/auth/authentik{inviteToken ? `?invite=${inviteToken}` : ''}">
|
providerName="authentik"
|
||||||
<input type="hidden" value={inviteToken} name="invite" />
|
displayName="Authentik"
|
||||||
<Button type="submit" disabled={submitted}>
|
iconSrc="https://auth.cazzzer.com/static/dist/assets/icons/icon.svg"
|
||||||
{#if submitted}
|
{inviteToken}
|
||||||
<LucideLoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
/>
|
||||||
{:else}
|
|
||||||
<img
|
|
||||||
class="mr-2 h-4 w-4"
|
|
||||||
alt="Authentik Logo"
|
|
||||||
src="https://auth.cazzzer.com/static/dist/assets/icons/icon.svg"
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
Sign in with Authentik
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
{/if}
|
{/if}
|
||||||
{#if enabledAuthProviders.google }
|
{#if enabledAuthProviders.google}
|
||||||
<form method="get" onsubmit={() => submitted = true}
|
<AuthButton providerName="google" displayName="Google" iconSrc={googleIcon} {inviteToken} />
|
||||||
action="/auth/google{inviteToken ? `?invite=${inviteToken}` : ''}">
|
|
||||||
<input type="hidden" value={inviteToken} name="invite" />
|
|
||||||
<Button type="submit" disabled={submitted}>
|
|
||||||
{#if submitted}
|
|
||||||
<LucideLoaderCircle class="mr-2 h-4 w-4 animate-spin" />
|
|
||||||
{:else}
|
|
||||||
<img
|
|
||||||
class="mr-2 h-4 w-4"
|
|
||||||
alt="Google Logo"
|
|
||||||
src={googleIcon}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
Sign in with Google
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,6 +2,7 @@ import type { LayoutServerLoad } from './$types';
|
|||||||
import { redirect } from '@sveltejs/kit';
|
import { redirect } from '@sveltejs/kit';
|
||||||
import { isValidInviteToken } from '$lib/server/auth';
|
import { isValidInviteToken } from '$lib/server/auth';
|
||||||
|
|
||||||
export const load: LayoutServerLoad = ({ params }) => {
|
export const load: LayoutServerLoad = ({ params, locals }) => {
|
||||||
if (!isValidInviteToken(params.id)) redirect(307, '/')
|
if (!isValidInviteToken(params.id)) redirect(302, '/');
|
||||||
|
if (locals.user !== null) redirect(302, '/');
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<h1 class="mb-2 scroll-m-20 text-center text-3xl font-extrabold tracking-tight lg:text-4xl">
|
<h1 class="mb-2 scroll-m-20 text-center text-3xl font-extrabold tracking-tight lg:text-4xl">
|
||||||
Welcome to VPGen
|
You are invited to VPGen
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<AuthForm inviteToken={inviteToken} />
|
<AuthForm {inviteToken} />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user