-
Notifications
You must be signed in to change notification settings - Fork 0
feat(aluno): auto-provision perfil on Google OAuth login #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,7 +34,74 @@ export default async function AlunoDashboardPage() { | |||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const aluno = await alunoPromise; | ||||||||||||||||||||||
| let aluno = await alunoPromise; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Auto-provision: OAuth users (Google/GitHub/Apple) who have no aluno row get | ||||||||||||||||||||||
| // one created lazily on first dashboard visit. Email+name come from Supabase | ||||||||||||||||||||||
| // auth.user_metadata; CPF is required @unique but unknown from Google, so we | ||||||||||||||||||||||
| // mint a deterministic placeholder from the auth user id (uniqueness from the | ||||||||||||||||||||||
| // already-unique auth uid). Admin can fix the real CPF later. Throws on the | ||||||||||||||||||||||
| // rare race where two concurrent requests both miss findUnique — caught below | ||||||||||||||||||||||
| // surfaces as the original empty-state so the next request finds the row. | ||||||||||||||||||||||
| if (!aluno) { | ||||||||||||||||||||||
| const meta = user.user_metadata ?? {}; | ||||||||||||||||||||||
| const nomeCompleto = | ||||||||||||||||||||||
| (meta.full_name as string | undefined) ?? | ||||||||||||||||||||||
| (meta.name as string | undefined) ?? | ||||||||||||||||||||||
| user.email ?? | ||||||||||||||||||||||
| 'Aluno Google'; | ||||||||||||||||||||||
|
Comment on lines
+48
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: OAuth users with an empty Prompt for AI agents
Suggested change
|
||||||||||||||||||||||
| const fotoUrl = (meta.avatar_url as string | undefined) ?? null; | ||||||||||||||||||||||
| const cpfPlaceholder = `OAUTH-${user.id.slice(0, 18)}`; | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| aluno = await prisma.aluno.create({ | ||||||||||||||||||||||
| data: { | ||||||||||||||||||||||
| email: user.email!, | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Inspect getUser return type and the User.email typing to confirm nullability.
fd -t f 'server.(ts|tsx)' src/utils/supabase --exec cat -n {}
rg -nP '\buser\.email\b' src/app/aluno/dashboard/page.tsxRepository: EmiyaKiritsugu3/PWeb_Project Length of output: 2170 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the dashboard page around the cited lines and the getUser helper.
file="src/app/aluno/dashboard/page.tsx"
echo "== file size =="
wc -l "$file"
echo "== relevant slices =="
sed -n '1,180p' "$file"
echo "== search for guards / redirects related to email =="
rg -n "email|redirect|notFound|throw|return null|optional|undefined" "$file"Repository: EmiyaKiritsugu3/PWeb_Project Length of output: 5913 🏁 Script executed: #!/bin/bash
set -euo pipefail
file="src/app/aluno/dashboard/page.tsx"
# Show tighter context around the reported lines.
sed -n '1,140p' "$file" | nl -ba | sed -n '1,140p'
# Also inspect the Supabase auth user type if it is vendored in the repo lock/types.
rg -n "type User|interface User|email\?:|email:.*undefined" . -g '!node_modules' -g '!dist' -g '!build'Repository: EmiyaKiritsugu3/PWeb_Project Length of output: 206 Handle 🤖 Prompt for AI Agents |
||||||||||||||||||||||
| nomeCompleto, | ||||||||||||||||||||||
| fotoUrl, | ||||||||||||||||||||||
| cpf: cpfPlaceholder, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| select: { | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The Prompt for AI agents |
||||||||||||||||||||||
| id: true, | ||||||||||||||||||||||
| nomeCompleto: true, | ||||||||||||||||||||||
| fotoUrl: true, | ||||||||||||||||||||||
| nivel: true, | ||||||||||||||||||||||
| exp: true, | ||||||||||||||||||||||
| statusMatricula: true, | ||||||||||||||||||||||
| streakDiasSeguidos: true, | ||||||||||||||||||||||
| treinosNoMes: true, | ||||||||||||||||||||||
| ultimoTreinoData: true, | ||||||||||||||||||||||
| Matriculas: { | ||||||||||||||||||||||
| where: { status: 'ATIVA' }, | ||||||||||||||||||||||
| orderBy: { dataVencimento: 'desc' }, | ||||||||||||||||||||||
| take: 1, | ||||||||||||||||||||||
| select: { id: true, status: true, dataVencimento: true, planoId: true }, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: First-time OAuth users can still land on the “perfil de aluno não foi encontrado” fallback for real create failures because this catches every Prompt for AI agents |
||||||||||||||||||||||
| // Race: another request created the row. Refetch instead of crashing. | ||||||||||||||||||||||
| aluno = await prisma.aluno.findUnique({ | ||||||||||||||||||||||
| where: { email: user.email }, | ||||||||||||||||||||||
| select: { | ||||||||||||||||||||||
| id: true, | ||||||||||||||||||||||
| nomeCompleto: true, | ||||||||||||||||||||||
| fotoUrl: true, | ||||||||||||||||||||||
| nivel: true, | ||||||||||||||||||||||
| exp: true, | ||||||||||||||||||||||
| statusMatricula: true, | ||||||||||||||||||||||
| streakDiasSeguidos: true, | ||||||||||||||||||||||
| treinosNoMes: true, | ||||||||||||||||||||||
| ultimoTreinoData: true, | ||||||||||||||||||||||
| Matriculas: { | ||||||||||||||||||||||
| where: { status: 'ATIVA' }, | ||||||||||||||||||||||
| orderBy: { dataVencimento: 'desc' }, | ||||||||||||||||||||||
| take: 1, | ||||||||||||||||||||||
| select: { id: true, status: true, dataVencimento: true, planoId: true }, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+81
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== file outline ==\n'
ast-grep outline src/app/aluno/dashboard/page.tsx --view expanded
printf '\n== relevant lines 1-170 ==\n'
cat -n src/app/aluno/dashboard/page.tsx | sed -n '1,170p'
printf '\n== prisma/aluno references in file ==\n'
rg -n "prisma\.aluno|Prisma|Sentry|catch" src/app/aluno/dashboard/page.tsx
printf '\n== imports at top ==\n'
sed -n '1,35p' src/app/aluno/dashboard/page.tsxRepository: EmiyaKiritsugu3/PWeb_Project Length of output: 7943 Narrow the 🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!aluno) { | ||||||||||||||||||||||
| return ( | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,8 +150,11 @@ max_indexes = 5 | |
| [auth] | ||
| enabled = true | ||
| # The base URL of your website. Used as an allow-list for redirects and for constructing URLs used | ||
| # in emails. | ||
| site_url = "http://localhost:3000" | ||
| # in emails. Must be the production URL — Supabase falls back to this when a `redirectTo` | ||
| # fails allowlist validation, so leaving it as localhost in a linked cloud project sends | ||
| # users to localhost on every OAuth redirect mismatch. Local dev resolves via | ||
| # additional_redirect_urls (localhost entry) instead. | ||
| site_url = "https://smartmanagementsystem.vercel.app" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Local password signup/email confirmation will now send developers to the production app when using the local Supabase stack. The Prompt for AI agents |
||
| # A list of *exact* URLs that auth providers are permitted to redirect to post authentication. | ||
| additional_redirect_urls = [ | ||
| "http://localhost:3000/auth/callback", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Custom agent: Enforce Pragmatic Test Coverage
The auto-provision logic is core business logic, but its success and failure paths are not exercised by the current tests.
page.test.tsxonly mocksprisma.aluno.findUniqueand does not cover the newprisma.aluno.createcall or the race-condition refetch in the catch block. Consider adding tests that mock a successful creation and simulate the unique-violation race case so both branches are validated.Prompt for AI agents