Robi
Robi
BABetter Auth
Created by Acro on 2/9/2025 in #help
SvelteKit Example
You can get the url and throw redirects from the hook with this method too , no ?
9 replies
BABetter Auth
Created by Acro on 2/9/2025 in #help
SvelteKit Example
or if you're using just the client and the instance isnt on your sveltekit but on an express server somewhere else hooks.server.ts
import type { Handle } from '@sveltejs/kit';

export const handle: Handle = async ({ event, resolve }) => {

const session = await authClient.getSession({
fetchOptions: {
headers: event.request.headers
}
});

event.locals.session = session?.data?.session;
event.locals.user = session?.data?.user;

const response = await resolve(event);
return response;
};
import type { Handle } from '@sveltejs/kit';

export const handle: Handle = async ({ event, resolve }) => {

const session = await authClient.getSession({
fetchOptions: {
headers: event.request.headers
}
});

event.locals.session = session?.data?.session;
event.locals.user = session?.data?.user;

const response = await resolve(event);
return response;
};
then to protect a route ( anything in (admin) for example )
import type { LayoutServerLoad } from './$types';
import { error, redirect } from '@sveltejs/kit';

export const load: LayoutServerLoad = async ({ locals }) => {

console.log('Admin Layout Server load ');

const session = locals.session;
const user = locals.user;

if (!session) {
console.log('Admin : No session');
throw redirect(302, '/login');
}
if (user?.role !== 'admin') {
console.log('Admin : Not admin');
throw error(403, 'Forbidden');
}
};
import type { LayoutServerLoad } from './$types';
import { error, redirect } from '@sveltejs/kit';

export const load: LayoutServerLoad = async ({ locals }) => {

console.log('Admin Layout Server load ');

const session = locals.session;
const user = locals.user;

if (!session) {
console.log('Admin : No session');
throw redirect(302, '/login');
}
if (user?.role !== 'admin') {
console.log('Admin : Not admin');
throw error(403, 'Forbidden');
}
};
9 replies
BABetter Auth
Created by Robi on 10/13/2024 in #bug-reports
light mode colored shadows are not that great
very sexy 💯
13 replies
BABetter Auth
Created by Robi on 10/13/2024 in #bug-reports
light mode colored shadows are not that great
that it does lolll
13 replies
BABetter Auth
Created by Robi on 10/13/2024 in #bug-reports
light mode colored shadows are not that great
imo better to get rid of the glow cus it will not let all the people with light mode read the code
13 replies
BABetter Auth
Created by Robi on 10/13/2024 in #bug-reports
light mode colored shadows are not that great
No description
13 replies
BABetter Auth
Created by Robi on 10/13/2024 in #bug-reports
light mode colored shadows are not that great
if i do dark > reload > light > reload = bug dark > light > reload = bug honestly reloading after choosing light is what does it ? its inconsistent let me do a screen cap
13 replies
BABetter Auth
Created by Robi on 10/13/2024 in #bug-reports
light mode colored shadows are not that great
hmm
13 replies
BABetter Auth
Created by Robi on 10/13/2024 in #bug-reports
light mode colored shadows are not that great
nope , goes away
13 replies