Skip to content

Commit

Permalink
Add Github signin/signup
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks committed Nov 1, 2023
1 parent 3475d84 commit 88707c7
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 3,442 deletions.
23 changes: 23 additions & 0 deletions app/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ def signin():
return render_template("auth/signin.html", form=form, next=next)


@auth.route("/signin/github")
def signin_with_github():
resp = supabase.auth.sign_in_with_oauth(
{
"provider": "github",
"options": {"redirect_to": f"{request.host_url}auth/callback"},
}
)
return redirect(resp.url)


@auth.route("/signup", methods=["GET", "POST"])
def signup():
form = AuthForm()
Expand Down Expand Up @@ -93,6 +104,18 @@ def confirm():
return redirect(url_for(next))


@auth.route("/callback")
def callback():
code = request.args.get("code")
next = request.args.get("next", "dashboard")

if code:
res = supabase.auth.exchange_code_for_session({"auth_code": code})
print(res)

return redirect(url_for(next))


@auth.route("/verify-token", methods=["GET", "POST"])
def verify_token():
auth_type = request.args.get("type", "email")
Expand Down
4 changes: 3 additions & 1 deletion app/supabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
def get_supabase() -> Client:
if "supabase" not in g:
g.supabase: Client = create_client(
url, key, options=ClientOptions(storage=FlaskSessionStorage())
url,
key,
options=ClientOptions(storage=FlaskSessionStorage(), flow_type="pkce"),
)
return g.supabase

Expand Down
410 changes: 196 additions & 214 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packages = [{ include = "app" }]

[tool.poetry.dependencies]
python = "^3.10"
supabase = "^2.0.1"
supabase = "^2.0.3"
flask = "^2.3.3"
flask-wtf = "^1.1.1"
email-validator = "^2.0.0.post2"
Expand Down
Loading

0 comments on commit 88707c7

Please sign in to comment.