Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lucia integration to use the new getRequestEvent functionality #493

Open
ollema opened this issue Mar 18, 2025 · 2 comments
Open
Labels
enhancement New feature or request pkg:add sv add

Comments

@ollema
Copy link

ollema commented Mar 18, 2025

I think it would make sense if this check:

export const load${ts(': PageServerLoad')} = async (event) => {
if (!event.locals.user) {
return redirect(302, '/demo/lucia/login');
}
return { user: event.locals.user };
};

was rewritten into a shared function using the new getRequestEvent

@dummdidumm
Copy link
Member

Why? Is this repeated in multiple places? (I'm not well-versed with this code, but it looks like this wouldn't give us anything)

@ollema
Copy link
Author

ollema commented Mar 18, 2025

Why? Is this repeated in multiple places? (I'm not well-versed with this code, but it looks like this wouldn't give us anything)

oh no it would not improve anything with this code since it's not repeated as you pointed out.

however I think it's a really good pattern to adhere to when it comes to auth guards, so to me it makes sense that you would include such a function in the code generated by the official svelte CLI if you understand what I mean.

as Rich wrote in the PR description:

It's also useful if you need to do auth stuff. For example we can make a utility function that redirects the user to /login if they're not logged in already

so I figured why not encourage just this use case?

most real sites have more than one protected route, if you have a protected route at all, so this will have to be rewritten and reused soon enough IMHO.


in a slightly similar vein, the lucia integration also adds a validatePassword which is not repeated and yet it is included because I assume it is good practice and it makes the good easier to read and maintain.

so maybe the only criteria is not "is this repeated in multiple places?", is what I am trying to get across, not sure if I succeeded.

@manuel3108 manuel3108 added enhancement New feature or request pkg:add sv add labels Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg:add sv add
Projects
None yet
Development

No branches or pull requests

3 participants