Search code examples
deadbolt-2

set cookie session deadbolt 2 in controller


I'm new deadbolt 2, code sample have hardcode check in MyDeadboltHandler AuthorisedUser.findByUserName("steve") and I see an other example 'final Http.Cookie userCookie = context.request().cookie("user");' in MyDeadboltHandler

but I don't know set cookie in controller Thank in advance


Solution

  • When your user logs in, you can just write the cookie directly into the session, and it will be passed to the client in the response.

    From the documentation

    public Result login() {
        session("connected", "[email protected]");
        return ok("Welcome!");
    }
    

    In your case, the cookie key is up to you to define, and the email address or username may come from a form submitted with the credentials.