Update main.py
Browse files
main.py
CHANGED
@@ -51,14 +51,22 @@ async def auth_callback(request: Request, db: Session = Depends(get_db)):
|
|
51 |
# Check if this user is already in your database, if not, create a new user record
|
52 |
db_user = db.query(User).filter(User.email == user_info['email']).first()
|
53 |
if not db_user:
|
54 |
-
db_user = User(email=user_info['email'], name=user_info['name'])
|
55 |
db.add(db_user)
|
56 |
db.commit()
|
57 |
db.refresh(db_user)
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
# Redirect
|
60 |
-
|
61 |
-
|
|
|
|
|
62 |
# Other routes and logic for your application...
|
63 |
|
64 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
51 |
# Check if this user is already in your database, if not, create a new user record
|
52 |
db_user = db.query(User).filter(User.email == user_info['email']).first()
|
53 |
if not db_user:
|
54 |
+
db_user = User(email=user_info['email'], name=user_info['name'], is_verified=True)
|
55 |
db.add(db_user)
|
56 |
db.commit()
|
57 |
db.refresh(db_user)
|
58 |
+
|
59 |
+
# Create an access token for the user
|
60 |
+
access_token = auth_views.create_access_token(
|
61 |
+
data={"sub": db_user.email},
|
62 |
+
expires_delta=timedelta(minutes=auth_views.ACCESS_TOKEN_EXPIRE_MINUTES)
|
63 |
+
)
|
64 |
|
65 |
+
# Redirect the user to the protected route
|
66 |
+
url = app.url_path_for("get_protected")
|
67 |
+
response = RedirectResponse(url)
|
68 |
+
response.set_cookie(key="access_token", value=f"Bearer {access_token}", httponly=True)
|
69 |
+
return response
|
70 |
# Other routes and logic for your application...
|
71 |
|
72 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|