Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Sep 18, 2023
1 parent 37ae7c8 commit e4c43f8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/authentication/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Here we just demonstrate the NiceGUI integration.
"""
from typing import Optional
from urllib.parse import quote

from fastapi import Request
from fastapi.responses import RedirectResponse
Expand All @@ -18,12 +17,14 @@
# in reality users passwords would obviously need to be hashed
passwords = {'user1': 'pass1', 'user2': 'pass2'}

unrestricted_page_routes = ['/login']
unrestricted_page_routes = {'/login'}


class AuthMiddleware(BaseHTTPMiddleware):
"""This middleware restricts access to all NiceGUI pages.
It redirects the user to the login page if they are not authenticated."""
It redirects the user to the login page if they are not authenticated.
"""

async def dispatch(self, request: Request, call_next):
if not app.storage.user.get('authenticated', False):
Expand All @@ -45,7 +46,7 @@ def main_page() -> None:

@ui.page('/subpage')
def test_page() -> None:
ui.label('This is a subpage page.')
ui.label('This is a sub page.')


@ui.page('/login')
Expand Down

0 comments on commit e4c43f8

Please sign in to comment.