-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from silentworks/develop
Latest update with some fixes to supabase-py
- Loading branch information
Showing
33 changed files
with
4,115 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.black-formatter" | ||
} | ||
}, | ||
"deno.enablePaths": [ | ||
"supabase" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from functools import wraps | ||
from typing import Union | ||
from flask import redirect, session, url_for, request | ||
from gotrue.errors import AuthApiError, AuthRetryableError | ||
from gotrue.types import Session | ||
from app.supabase import get_profile_by_user, supabase | ||
|
||
|
||
def login_required(f): | ||
@wraps(f) | ||
def decorated(*args, **kwargs): | ||
sess: Union[Session, None] = None | ||
try: | ||
sess = supabase.auth.get_session() | ||
# TODO: remove workaround once | ||
# https://github.com/supabase-community/supabase-py/pull/560 is merged and released | ||
# supabase.postgrest.auth(token=sess.access_token) | ||
except AuthApiError as exception: | ||
err = exception.to_dict() | ||
if err.get("message") == "Invalid Refresh Token: Already Used": | ||
sess = None | ||
except AuthRetryableError: | ||
return redirect(url_for("service_unavailable")) | ||
|
||
if sess is None: | ||
return redirect(url_for("auth.signin", next=request.endpoint)) | ||
|
||
return f(*args, **kwargs) | ||
|
||
return decorated | ||
|
||
|
||
def password_update_required(f): | ||
@wraps(f) | ||
def decorated(*args, **kwargs): | ||
if "password_update_required" in session: | ||
return redirect(url_for("account.update_password")) | ||
|
||
return f(*args, **kwargs) | ||
|
||
return decorated | ||
|
||
|
||
def profile_required(f): | ||
@wraps(f) | ||
def decorated(*args, **kwargs): | ||
incomplete_profile = False | ||
try: | ||
# get profile and profile_info | ||
profile = get_profile_by_user() | ||
|
||
if profile and profile["display_name"] is None: | ||
incomplete_profile = True | ||
except AuthApiError: | ||
incomplete_profile = True | ||
except AuthRetryableError: | ||
incomplete_profile = True | ||
|
||
if incomplete_profile: | ||
return redirect(url_for("account.update")) | ||
|
||
return f(*args, **kwargs) | ||
|
||
return decorated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.