Spaces:
Sleeping
Sleeping
Update app/main.py
Browse files- app/main.py +19 -11
app/main.py
CHANGED
|
@@ -113,22 +113,30 @@ def auth_google():
|
|
| 113 |
|
| 114 |
@app.get("/oauth2callback")
|
| 115 |
def oauth2callback(request: Request):
|
| 116 |
-
|
|
|
|
| 117 |
|
| 118 |
-
|
|
|
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
|
| 123 |
-
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
|
| 134 |
@app.get("/auth/status")
|
|
|
|
| 113 |
|
| 114 |
@app.get("/oauth2callback")
|
| 115 |
def oauth2callback(request: Request):
|
| 116 |
+
try:
|
| 117 |
+
code = request.query_params.get("code")
|
| 118 |
|
| 119 |
+
if not code:
|
| 120 |
+
return HTMLResponse("Erro: código OAuth não recebido.", status_code=400)
|
| 121 |
|
| 122 |
+
flow = build_flow()
|
| 123 |
+
flow.fetch_token(code=code)
|
| 124 |
|
| 125 |
+
save_credentials(flow.credentials)
|
| 126 |
|
| 127 |
+
return HTMLResponse("""
|
| 128 |
+
<h2>✅ Google Sheets autorizado com sucesso!</h2>
|
| 129 |
+
<p>Agora o backend já pode salvar feedbacks na planilha.</p>
|
| 130 |
+
""")
|
| 131 |
|
| 132 |
+
except Exception as e:
|
| 133 |
+
return HTMLResponse(
|
| 134 |
+
f"""
|
| 135 |
+
<h2>Erro no OAuth callback</h2>
|
| 136 |
+
<pre>{type(e).__name__}: {str(e)}</pre>
|
| 137 |
+
""",
|
| 138 |
+
status_code=500
|
| 139 |
+
)
|
| 140 |
|
| 141 |
|
| 142 |
@app.get("/auth/status")
|