SurfSense icon indicating copy to clipboard operation
SurfSense copied to clipboard

Access `/settings` when not logged in is not handled gracefully

Open NatsumeRyuhane opened this issue 4 months ago • 4 comments

Problem

As in title, accessing /settings while not logged in will display page errors instead of being redirected to login or home page.

This is just an example endpoint I find, and more comprehensive testing on other pages that require authentication to access should also be tested.

Screenshot

Image

NatsumeRyuhane avatar Oct 02 '25 18:10 NatsumeRyuhane

@NatsumeRyuhane Would you like to refine the non auth fallback. I think this issue will be true for every page. Better to redirect to /login .What do you think?

MODSetter avatar Oct 03 '25 05:10 MODSetter

I can take this. Should be an easy fix, but need to be tested throughly. Do we have a list of API or something?

NatsumeRyuhane avatar Oct 03 '25 06:10 NatsumeRyuhane

Okay, after a quick check I found that we do have a handler function defined for this behavior /lib/api.ts: fetchWithAuth, but It appears a lot of places where we should use this function was implemented with raw fetch instead.

NatsumeRyuhane avatar Oct 03 '25 06:10 NatsumeRyuhane

I can take this. Should be an easy fix, but need to be tested throughly. Do we have a list of API or something?

Basically, the current auth flow works like this:

  • We get the access token from the backend and send it to the frontend.
  • The frontend stores it in localStorage as surfsense_bearer_token.
  • Then, we include that token in further API requests.

So, I think we should redirect to /login whenever we get a 401 from the backend at any API call.

Okay, after a quick check I found that we do have a handler function defined for this behavior /lib/api.ts: fetchWithAuth, but It appears a lot of places where we should use this function was implemented with raw fetch instead.

Weird. If I remember it correctly I faced some issues when I used this wrapper. Maybe you can try again and try to fix that.

MODSetter avatar Oct 03 '25 06:10 MODSetter