Spark API says Unauthorized

Published 1 year ago by christopher

Here i am fetching my Categories. This is the route of the API and the Controller is returning all categories

But if you go to the Demo Page the select form does not fetch anything from the API because the Network Tab says its ​Unauthorized.

If i am logged in its working, as soon as i am logged out the API is returning ​Unauthorized.

Does someone know why?

tnorthcutt

Looks like that route uses the auth:api middleware, so you wouldn't expect it to work when logged out, right? Unless you're passing the token in your request, in which case I'd suggest comparing the request when logged out and when logged in to see what the difference is.

christopher

@tnorthcutt I watched the API Driven Development series from Taylor. I understood it like so that i only need the Token if i make an external Request to the API.

Or am i wrong and i need the token because i am logged out? e.g i make an external request because i am not logged in

If so it would be crap :) I dont want to make an extra token for the actual application.

Is there any i can do to go around this to not generate a token for the actual app?

tnorthcutt

Not sure - I'm new to Spark too :). This may be of interest, though. Taken from this thread, which it looks like you've seen.

douglas_quaid

@christopher did you figure out a way around this? I'm having the same problem and getting 401 (unauthorized) when I try to make a call to the API when I'm not logged in (as a Guest). Assuming it's treating this because I have the auth middleware on all API routes. How did you fix this?

envision

@douglas_quaid did you get that solved?

Please sign in or create an account to participate in this conversation.