Skip to content

FastAPI-users how to login, logout (register) behind routes? #1286

Answered by NickNaskida
MuzykaAndrii asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a guide to authentication implementation in SQLAdmin - Authentication - SQLAlchemy Admin

You should implement needed crud methods on User model (which is available if you are using FastAPI-users)

Here is a snippet of my code (I use starlette admin)

class AdminAuthProvider(AuthProvider):
    """Custom authentication provider for admin."""
    async def login(
        self,
        username: str,
        password: str,
        remember_me: bool,
        request: Request,
        response: Response,
    ) -> Response:
        # check if user exists
        user = await crud.user.get_by_email(email=username, db_session=db.session)

        if not user:
            raise LoginFailed("I…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by MuzykaAndrii
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants