File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { superValidate } from 'sveltekit-superforms' ;
2+ import { valibot } from 'sveltekit-superforms/adapters' ;
3+ import * as v from 'valibot' ;
14import type { Actions , PageServerLoad } from './$types' ;
25import { returnTo , tryVerifyCookie } from '$lib/server/auth' ;
36import { QueueConnected } from '$lib/server/bullmq' ;
47
8+ const loginSchema = v . object ( {
9+ returnTo : v . optional ( v . string ( ) )
10+ } ) ;
11+
512export const load : PageServerLoad = async ( event ) => {
613 return {
7- serviceAvailable : QueueConnected ( )
14+ serviceAvailable : QueueConnected ( ) ,
15+ form : await superValidate ( valibot ( loginSchema ) )
816 } ;
917} ;
1018export const actions : Actions = {
1119 async login ( event ) {
20+ const form = await superValidate ( event . request , valibot ( loginSchema ) ) ;
21+ if ( form . valid && form . data . returnTo ) {
22+ event . url . searchParams . set ( 'returnTo' , form . data . returnTo ) ;
23+ }
1224 await tryVerifyCookie ( event , false ) ;
1325 throw returnTo ( event ) ;
1426 }
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import { onDestroy } from ' svelte' ;
3+ import { superForm } from ' sveltekit-superforms' ;
34 import type { PageData } from ' ./$types' ;
45 import { browser } from ' $app/environment' ;
6+ import { page } from ' $app/state' ;
57 import { env } from ' $env/dynamic/public' ;
68 import ScriptoriaIcon from ' $lib/icons/ScriptoriaIcon.svelte' ;
79
2931 timeout = null ;
3032 }
3133 });
34+
35+ const { enhance } = superForm (data .form , {
36+ onSubmit(event ) {
37+ const returnTo = page .url .searchParams .get (' returnTo' );
38+ if (returnTo ) {
39+ event .formData .set (' returnTo' , returnTo );
40+ }
41+ }
42+ });
3243 </script >
3344
3445<div class =" card shadow-xl bg-white border p-4" >
4253 BuildEngine serves as an interface between Scriptoria and the AWS resources it uses.
4354 </p >
4455 {#if data .serviceAvailable }
45- <form method =" POST" action =" ?/login" class =" w-full" >
56+ <form method =" POST" action =" ?/login" class =" w-full" use:enhance >
4657 <button class =" btn btn-primary w-full" >Login with Scriptoria</button >
4758 </form >
4859 {:else }
You can’t perform that action at this time.
0 commit comments