-
Notifications
You must be signed in to change notification settings - Fork 2
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
Using authOptional
in :api
pipelines
#97
Comments
@LuchoTurtle great question, thank you for asking/opening it. 👌 |
I've pondered about this and tried to find a way to handle this but perhaps it's best for the user to do the fetching of the session themselves. Auth_plug shouldn't fetch the session just to verify if it exists. This will cause fetching the session two times when using a browser pipeline, which is not really bueno. |
Exactly. Thanks for confirming. 👌 |
@LuchoTurtle do you want to add a brief section on how to use |
Just created #102 to briefly explain how to use this package with APIs. Nothing biggie, just a clarification. |
Thanks very much @LuchoTurtle 👍 |
I'm trying to use this plug in an
:api
pipeline.Having read the documentation, doing
pipeline :authoptional, do: plug(AuthPlugOptional, %{})
should be enough to get up and going.
Adding this pipeline to the scope should be fairly simple, like so:
However, I keep stumbling upon this error when calling the app anonymously.
session not fetched, call fetch_session/2
This error doesn't occur when I add a
Bearer Token
, for example.This error occurs in
auth_plug
and I've located where. The error is inget_jwt
, when callingget_session
..It's weird, this error shouldn't be happening according to the
Conn.Plug
's source code, since the:jwt
atom is being passed.I'm aware this could easily be surpassed by just creating the
authOptional
pipeline with aplug:fetch_session
, like so:However, I feel like
auth_plug
should gracefully handle these scenarios.Should a guard be added in
get_jwt
? Or is it the user's responsibility tofetch_session
in their:authOptional
pipelines?The text was updated successfully, but these errors were encountered: