Skip to content

auth.attempt() returns None when once=True #836

@ReS4

Description

@ReS4

Describe the bug

The function auth.attempt() should return the user model when the parameter once is set to True, but currently, it returns None instead.

Expected behaviour

auth.attempt() must return the user model when the credentials are valid whether the once parameter is set or not.

Steps to reproduce the bug

user = auth.attempt(request.input("email"), request.input("password"), once=True)
if user: # user is always None
    print(user.id)

Masonite Version

4.20.0

Anything else ?

the Default WebGuard's attempt method can be rewritten to something like this:

masonite.authentication.guards.WebGuard.py

def attempt(self, username, password):
    attempt = self.options.get("model")().attempt(username, password)
    if attempt and not self.options.get("once"):
        self.application.make("response").cookie("token", attempt.remember_token)
        self.application.make("request").set_user(attempt)
    return attempt # change this line

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions