Switch to using /api/session/validate for determining if the user is not logged in
#34
Reference in New Issue
Block a user
Delete Branch "frontend/login"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
My apologies for being stupid not knowing the NextJS framework fully, as I have little experience with it and its non intuitive SSR and CSR workflow
Code successfully built locally running
bun run buildWhy is this checking
logged_in.code === 500? Shouldn't the json just be a boolean value?I used what the response would be if you're not logged in
Should
login_check()beawait login_check()in theuseEffect(() => {body?Why is the not logged in response an internal server error 😭
According to:
Its valid and should work the same
Is it going to be changed away from a code 500 error? the message it returned along side seemed like a reasonable error message to be seeing from an API if you're not logged in so I assumed it was ok to use that,
I liked the idea of using a
.code === 500over aif (logged_in)because JS is a highly unsafe and unpredictable languageI looked into it and the reason it does that is because the openapi spec defaults to requiring security for all requests, so you need to have a valid session to check if your session is valid 💀
I don't know if there is a way to have opt-out security for requests, I have only seen opt-in.
Switch to using `/api/session/validate` for determining if the user is not logged into WIP: Switch to using `/api/session/validate` for determining if the user is not logged in0d2cd5fb49to8b06a1414dWorking on making the validate endpoint make sense. I've discovered a way to specify opt-out security for the openapi spec (#35). I also rebased this branch top of the conflicting patch.
I saw itzaname's suggestion in
#developmentabout doingoauth2/login?redirect=https://maps.staging.strafes.netIm gonna implement that here and utilize NextJS's libraries for reading the url and appending the current page url to
?redirect=instead of justhttps://maps.staging.strafes.netI've disabled implicit session validation inside the cookie auth handler (#36). This means that the request doesn't fail at the security stage anymore and can go ahead and check the session validity itself. This applies to all requests, but other auth requests (user, roles) with an invalid session will fail as expected, so it does not need to be pre-checked as it was.
The
/api/session/validateendpoint now returns true or false with errors only occurring due to other factors.Ok here's my theory:
await= greedy futures like callingtokio::spawn(login_check)that does not wait for it to completeawait= polled future like callinglogin_check().awaitthat waits for it to completeRust wins again
Yep, async functions without calling an
awaiton them will also return aPromise<T>, allowing shenanigans like this:?redirect=with auth redirection and switch to a boolean check for/api/session/validateWIP: Switch to using `/api/session/validate` for determining if the user is not logged into Switch to using `/api/session/validate` for determining if the user is not logged in