Replies: 2 comments 4 replies
-
I suspect the reason you've had no responses to this is because it's difficult to really make sense of the question. I suggest as a first step you decide where auth is going to happen and how - is the auth state completely client-side (the sort you get if you use firebase' auth default for example) or is your app going to run server-side in order to decide if access to a page is allowed? The problem with the latter is that it doesn't really fit with using the static-adapter - you don't normally have auth to restrict access to static pages of a site (unless it's 100% SSR) but instead to the data that those static pages may load. Presumably you want the auth to load data provided by your java app (?) There are lots of options for handling auth and SK provides pieces to use to make it easier (i.e. the session mechanism) but the setup you describe is probably going to make it way more complicated than it needs to be. First step is deciding if you need to use SSR, an SPA or hybrid (both), where the auth state will live, and where that auth state needs to be used to grant or deny access to anything. Once you have those you can then get into the specifics of how to implement things. |
Beta Was this translation helpful? Give feedback.
-
@CaptainCodeman OK, so this is something that I think would work pretty well, but I think that it is not 100% supported by the svelte: What is think is currently not there:
Now, my question is - is this kind of setup something that is normally implemented this way? Responding to your questions - as you can see from this current setup, I guess it is both, so SPA + SSR, where SPA would be SPA-login-only, SPA-USER-role, SPA-ADMIN-role. AUTH state lives in JWT token on the client side. JWT token is evaluated on the server side when requesting any endpoint (no matter if it is |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the problem
I have an app using sveltekit + java as backend. I use
@sveltejs/adapter-static
to pack svelte app and serve it from java server as.html
files. I'm using simplest JWT token stored in cookie to do auth on the server. The question I have is - what is the proper way to do auth in this case?This is option 1:
Here, client requests the page, and if he does not provide proper
"Cookie: access_token=jwttokenhere"
in the header, java server will redirect him directly to the/auth/login
page and then the client will get that URL from sveltekit built files.The problems I have here:
goto("/");
command inside the sveltekit route, svelte does not care if user is authorized or not, it will redirect no matter what. So I have to use insteadOption 2:
Here, index page is loaded from the server without any check if user authenticated or not. Then sveltekit needs somehow to know if user is authenticated. I saw that we can use here this method
export async function load({ page, fetch, session, stuff })
as an interceptor, and check if some variable is set - if not then we redirect. So here, there is no logic from the server related to redirects - server would only return status codes 401 if not authorized.The problems I see here:
fetch
to the server, server will issue 401.load
function just to fetchwhoami
endpoint for example - in order to see if currently authenticated - this is costly on every route change.Describe the proposed solution
No solution. Just asking what are possible alternatives to described use-cases.
Alternatives considered
No response
Importance
nice to have
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions