As this package is not published in Hackage, you should install it locally as a git submodule for your project.
- In the directory of your project where you put external dependancies (usually
deps
orlib
):
# Add the repo as a submodule to your project
git submodule add https://github.com/axel-angel/yesod-auth-token.git
- In your cabal file, under
build-depends
addyesod-auth-token
- Let
stack
know about the location of this package by adding it instack.yml
under:
# ...
packages:
- '.'
- 'lib/yesod-auth-token' # Change the dir name if needed
- Execute
stack build
to finish the installation
To put in your Foundation.hs
import Yesod.Auth.Token
instance YesodAuthToken App where
type AuthTokenId App = UserId
setUserToken uid t = do
runDB $ updateWhere [UserId ==. uid] [UserToken =. t]
getTokenCreds t = do
mUser <- runDB . getBy $ UniqueToken t
return $ (\uid -> TokenCreds (entityKey uid) t) <$> mUser
-- stuff in between
instance YesodAuth App where
-- stuff
getAuthId (Creds "token" t _) = do
mTokenCreds <- getTokenCreds t
return $ tokenCredsAuthId <$> mTokenCreds
-- You can add other plugins like BrowserID, email or OAuth here
authPlugins _ = [authToken]
In your model, you can have this
User
token Text
nickname Text Maybe
UniqueToken token
deriving Typeable