Skip to content

Commit 6ed1442

Browse files
code review
1 parent 83f9835 commit 6ed1442

File tree

1 file changed

+8
-7
lines changed
  • examples/google_one_tap_auth

1 file changed

+8
-7
lines changed

examples/google_one_tap_auth/main.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,37 @@
99
from nicegui import app, ui
1010

1111
# Get your Google Client ID from the Google Cloud Console and pass it as an environment variable (or write it to an .env file)
12-
# For local development, you should add http://localhost:8080 to the authorized javascript origins
13-
# In production, you should add the domain of your website to the authorized javascript origins
14-
# see https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid#get_your_google_api_client_id
12+
# For local development, you should add http://localhost:8080 to the authorized JavaScript origins.
13+
# In production, you should add the domain of your website to the authorized JavaScript origins.
14+
# See https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid#get_your_google_api_client_id.
1515
load_dotenv()
1616
GOOGLE_CLIENT_ID = os.environ.get('GOOGLE_CLIENT_ID', '')
1717

1818

1919
@ui.page('/')
20-
def main_page():
20+
def main_page() -> None:
2121
user_data = app.storage.user.get('user_data', None)
2222
if not user_data:
2323
ui.add_head_html('<script src="https://accounts.google.com/gsi/client" async defer></script>')
2424
ui.html(f'''
2525
<div id="g_id_onload"
2626
data-client_id="{GOOGLE_CLIENT_ID}"
2727
data-login_uri="http://localhost:8080/auth">
28-
</div>''')
28+
</div>
29+
''')
2930
ui.label('Sign in with Google One Tap')
3031
else:
3132
ui.label(f'Welcome {user_data["name"]}!')
3233
ui.button('Logout', on_click=logout)
3334

3435

35-
def logout():
36+
def logout() -> None:
3637
del app.storage.user['user_data']
3738
ui.navigate.to('/')
3839

3940

4041
@app.post('/auth')
41-
async def google_auth(credential: str = Form(...)):
42+
async def google_auth(credential: str = Form(...)) -> RedirectResponse:
4243
async with httpx.AsyncClient() as http_client:
4344
response = await http_client.get(f'https://oauth2.googleapis.com/tokeninfo?id_token={credential}')
4445
if response.status_code != 200:

0 commit comments

Comments
 (0)