Skip to content

feat(aluno): onboarding form for real CPF + address on OAuth login#198

Merged
EmiyaKiritsugu3 merged 2 commits into
mainfrom
feat/aluno-onboarding-form
Jul 8, 2026
Merged

feat(aluno): onboarding form for real CPF + address on OAuth login#198
EmiyaKiritsugu3 merged 2 commits into
mainfrom
feat/aluno-onboarding-form

Conversation

@EmiyaKiritsugu3

@EmiyaKiritsugu3 EmiyaKiritsugu3 commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

First Google OAuth login for a user with no alunos row now redirects to /aluno/onboarding to collect a real CPF + CEP + address, instead of auto-provisioning a placeholder-CPF row (OAUTH-${user.id.slice(0,18)}).

  • /aluno/dashboard: removed 60-line placeholder auto-provision block → if (!aluno) redirect('/aluno/onboarding').
  • /aluno/onboarding (new): server gate — no session → /aluno/login, existing row → /aluno/dashboard (idempotent), else renders <OnboardingClient />.
  • completeOnboardingAction (new server action): reads email/nomeCompleto/fotoUrl from the authenticated Supabase session (not the form → anti-spoof), re-validates the payload with OnboardingBaseSchema, creates the row. On P2002 (concurrent submit race) refetches by email → surfaces success.
  • OnboardingClient (new client form): all fields required (CPF, telefone, dataNascimento, CEP, endereco, numero, bairro, cidade, estado). Masks CPF/CEP/phone. ViaCEP lookup on CEP onBlur fills endereco/bairro/cidade/estado; on erro:true or network failure leaves fields empty (manual-entry fallback). Schema mirrored locally to keep server definitions.ts out of the browser bundle.

Schema

prisma/schema.prisma — 6 nullable String columns on alunos before statusMatricula: cep, endereco, numero, bairro, cidade, estado. No migration file (project uses prisma db push); cloud Supabase needs manual ALTER TABLE:

ALTER TABLE alunos ADD COLUMN IF NOT EXISTS cep TEXT;
ALTER TABLE alunos ADD COLUMN IF NOT EXISTS endereco TEXT;
ALTER TABLE alunos ADD COLUMN IF NOT EXISTS numero TEXT;
ALTER TABLE alunos ADD COLUMN IF NOT EXISTS bairro TEXT;
ALTER TABLE alunos ADD COLUMN IF NOT EXISTS cidade TEXT;
ALTER TABLE alunos ADD COLUMN IF NOT EXISTS estado TEXT;

CPF validation

OnboardingBaseSchema validates format (^\d{3}\.\d{3}\.\d{3}-\d{2}$) and check digits via cpfCheckDigit() — rejects all-equal-digit patterns, computes both verifiers per the standard CPF algorithm.

Tests

  • onboarding.test.ts — 4 tests: full-address create, no-auth error, invalid-check-digit rejection, P2002 race refetch.
  • onboarding-client.test.tsx — 2 tests: ViaCEP fills 4 fields, erro:true fallback leaves empty.
  • onboarding/page.test.tsx — 3 tests: redirect-to-login, redirect-to-dashboard (existing row), render-client.
  • dashboard/page.test.tsx — updated: null-aluno → NEXT_REDIRECT to /aluno/onboarding.

All 1173 tests pass, typecheck + lint green.

Carried-over

supabase/config.toml site_url → production URL (auth-redirect fix; onboarding depends on OAuth redirect working).

🤖 Generated with Claude Code


Summary by cubic

First OAuth login now redirects users without an alunos row to /aluno/onboarding to collect a real CPF and full address, replacing the placeholder-CPF auto-provision. Adds a server action to create the profile from session data with strict CPF validation and ViaCEP autofill.

  • New Features

    • /aluno/dashboard: if no aluno, redirect to /aluno/onboarding (removed placeholder provision).
    • /aluno/onboarding: guards session; skips form when a row exists; renders OnboardingClient.
    • completeOnboardingAction: reads email/name/photo from Supabase session, validates with OnboardingBaseSchema (CPF check digits), handles P2002 race by refetching, then revalidates the dashboard path.
    • OnboardingClient: required fields (CPF, telefone, dataNascimento, CEP, endereço, número, bairro, cidade, estado) with masks; ViaCEP on CEP blur fills address; manual-entry fallback.
    • supabase/config.toml: set site_url to production to fix OAuth redirect allowlist.
  • Migration

    • Add nullable TEXT columns on alunos: cep, endereco, numero, bairro, cidade, estado. For Supabase cloud (project uses prisma db push), run ALTER TABLE to add these columns before deploying.

Written for commit ac3d258. Summary will update on new commits.

Review in cubic

EmiyaKiritsugu3 and others added 2 commits July 8, 2026 10:18
Google OAuth users had no aluno row, landing on 'perfil não encontrado'
empty-state. Lazy-provision on first /aluno/dashboard visit:
- findUnique miss -> prisma.aluno.create with email + user_metadata
  (full_name, avatar_url) + deterministic CPF placeholder OAUTH-<uid14>
- race guarded: concurrent-create catch refetches
- same pattern applies to GitHub/Apple OAuth providers

Also fix site_url fallback (was localhost, sent OAuth mismatches to
localhost root with ?code=): set to production domain. Local dev still
works via additional_redirect_urls localhost entry.

Co-Authored-By: Claude <noreply@anthropic.com>
Replace placeholder-CPF auto-provision with redirect to /aluno/onboarding.

completeOnboardingAction reads email/nome/foto from Supabase session (anti-spoof),

validates via OnboardingBaseSchema with CPF check-digit verification, creates the

aluno row with cep/endereco/numero/bairro/cidade/estado. Client form mirrors the

schema locally; ViaCEP lookup on CEP blur with manual-entry fallback. Idempotent:

P2002 race refetch by email. Schema adds 6 nullable address columns.
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
smartmanagementsystem Ready Ready Preview, Comment Jul 8, 2026 2:02pm

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@EmiyaKiritsugu3, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 88eab0b1-6af7-4bca-8f6a-6ee0fe5f9423

📥 Commits

Reviewing files that changed from the base of the PR and between 368e765 and ac3d258.

📒 Files selected for processing (11)
  • prisma/schema.prisma
  • src/app/aluno/dashboard/page.test.tsx
  • src/app/aluno/dashboard/page.tsx
  • src/app/aluno/onboarding/onboarding-client.test.tsx
  • src/app/aluno/onboarding/onboarding-client.tsx
  • src/app/aluno/onboarding/page.test.tsx
  • src/app/aluno/onboarding/page.tsx
  • src/lib/actions/onboarding.test.ts
  • src/lib/actions/onboarding.ts
  • src/lib/definitions.ts
  • supabase/config.toml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/aluno-onboarding-form

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ecc-tools

ecc-tools Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@EmiyaKiritsugu3 EmiyaKiritsugu3 merged commit 3161975 into main Jul 8, 2026
14 checks passed
@EmiyaKiritsugu3 EmiyaKiritsugu3 deleted the feat/aluno-onboarding-form branch July 8, 2026 14:15
@EmiyaKiritsugu3 EmiyaKiritsugu3 restored the feat/aluno-onboarding-form branch July 8, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant