Skip to content
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

Logout user in Redirects.ex #311

Open
stenionobres opened this issue Dec 2, 2017 · 2 comments
Open

Logout user in Redirects.ex #311

stenionobres opened this issue Dec 2, 2017 · 2 comments

Comments

@stenionobres
Copy link

How to I have proceed for logout a user in a Redirects.ex?

I am checking if a user has permission to log in on a specific day, but when he's not allowed I am not able to log out the session. When the function session_create is called I need to log out the user before redirects.

I tried to use Coherence.SessionController.delete/2 but does not work, tried import, use, alias and nothing worked.

Tried to call redirect(conn, to: session_path(conn, :delete)), but the it seems to call a GET verb instead DELETE and therefore, do not work too.

So I am stuck, helpless. Can anybody help?

@smpallen99
Copy link
Owner

I would create a new plug and added it to the router pipeline before the coherence plug.
There, you can check if the user is logged in and should be prevented. If user is not logged in or if date constraint is satisfied, then just return conn, and the flow will continue normally.

Otherwise, call Coherence.ControllerHelpers.logout_user/1, redirect and halt. The halt will prevent the call of any following plugs.

@junjizhi
Copy link

@stenionobres Just curious. Did you try what @smpallen99 suggested?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants