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

How do I "remove" a session? #22

Open
abailly opened this issue Nov 25, 2016 · 12 comments
Open

How do I "remove" a session? #22

abailly opened this issue Nov 25, 2016 · 12 comments

Comments

@abailly
Copy link
Contributor

abailly commented Nov 25, 2016

There is a comment hinting at some way to do that:

----------------------------------------------------------------------------
-- Add/remove session

-- | Add cookie header to response. The function can throw the same
-- exceptions as 'encryptSession'.
addSession

but no corresponding function.

@ThomasCrevoisier
Copy link

Hey @abailly,

I'm currently using removeSession but struggle with it. Do you have a code sample to see how you integrate it in a Servant app ?

@abailly
Copy link
Contributor Author

abailly commented Jan 13, 2017

Hello,
Here is a place where I use it in my code:

doLogout :: AuthCookieSettings -> UserAccount -> m ()
doLogout settings _ = lift (removeSession settings ())

It's very simple actually... The tricky part is to understand where the session comes from.

@ThomasCrevoisier
Copy link

@abailly Thanks for your reply !

My api is defined like this

"api" :> "logout" :> AuthProtect "cookie-auth" :> Get '[JSON] (Headers '[Header "Set-Cookie" ByteString] ())

And for the moment the handler looks like yours : logoutServer _ = removeSession settings ()

Though, I've got this error :

No instance for (ToHttpApiData ByteString)
        arising from a use of ‘removeSession’

And I don't quite understand where the problem is 🤔

@abailly
Copy link
Contributor Author

abailly commented Jan 13, 2017

I have similar code and it works like a charm, except the action is POST and not a GET. For each AuthProtect a you have to define which type is computed by type family AuthServerData, e.g. :

type instance AuthServerData (AuthProtect "cookie-auth") =  X

it might be that X leads to some type which requires implementation of ToHttpApiData ?

@ThomasCrevoisier
Copy link

I was inspired by what's in the example/ folder so I didn't had to write type instance AuthServerData ... until now.

Here is the code if you have the time to take a quick look (sorry it's a bit drafty...)

@abailly
Copy link
Contributor Author

abailly commented Jan 13, 2017

It compiles OK here... Might be a version problem?

@ThomasCrevoisier
Copy link

ThomasCrevoisier commented Jan 13, 2017

Arf, damned >.< Which stackage resolver are you using ?

@abailly
Copy link
Contributor Author

abailly commented Jan 13, 2017 via email

@ThomasCrevoisier
Copy link

Do you point directly to the github repo of servant-auth-cookie ? I don't find the version 4.2 in this snapshot

@abailly
Copy link
Contributor Author

abailly commented Jan 13, 2017 via email

@ThomasCrevoisier
Copy link

Could you share your stack.yaml please ? ^^

@abailly
Copy link
Contributor Author

abailly commented Jan 13, 2017 via email

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

2 participants