Proposal/teacher onboarding mvp
Checklist:
- [x] I have read freeCodeCamp's contribution guidelines.
- [x] My pull request has a descriptive title (not a vague title like
Update index.md)
This PR is not associated with a specific issue
Case Study (Teacher Invite Acceptance Flow)
- Admin creates/resends a teacher invite from the admin dashboard.
- System sends a secure email link:
/teacher/invite/<token>. - Invited teacher signs in with the invited email.
- Teacher accepts invite.
- Invitation becomes
ACCEPTEDand user role is set toTEACHER.
What Changed (and Why)
-
Teacher invite backend APIs to support create/list/resend/revoke and secure acceptance. Reason: completes the core onboarding lifecycle with role-safe state transitions. Files:
-
pages/api/admin/teacher_invites/create.js
-
pages/api/admin/teacher_invites/list.js
-
pages/api/admin/teacher_invites/resend.js
-
pages/api/admin/teacher_invites/revoke.js
-
pages/api/teacher_invites/accept.js
-
util/inviteApiUtils.js
-
Email delivery + feature flag rollout support. Reason: enables controlled rollout and real invitation delivery. Files:
-
util/inviteEmail.js
-
util/featureFlags.js
-
package.json
-
package-lock.json
-
Admin + teacher UI flow. Reason: gives a usable end-to-end path from invite creation to invite acceptance. Files:
-
components/TeacherInvitesPanel.js
-
components/TeacherInvitesPanel.module.css
-
pages/admin/index.js
-
pages/teacher/invite/[inviteToken].js
-
styles/Home.module.css
-
pages/error.js
-
Data model + migration for invitation lifecycle. Reason: persists invitation state and supports expiry/revoke/accept transitions. Files:
-
prisma/schema.prisma
-
prisma/migrations/20260409192210_add_invitation_models/migration.sql
-
Env/security/docs updates. Reason: prevent future secret leaks and keep setup clear with tracked templates. Files:
-
.gitignore
-
.env.sample
-
.env.development.example
-
.env.production.example
-
README.md
-
.env.development/.env.productionremoved from tracking
Validation
npm run lint:codenpm test
How to Test
Prerequisites
This branch allows you to create an ADMIN account and send out email invitations to users to onboard as teachers.
You need:
- 1 "Admin" email (to serve as your ADMIN, and set up your Classroom account)
- 1+ extra "Teacher" emails (to receive email invites and onboard as teachers)
Configuring this branch for local development
- Create a local branch that tracks the
CarlyAThomas:proposal/teacher-onboarding-mvpbranch. - Run
cp .env.development.example .env.development - Update
SMTP_USERin.env.developmentwith your Admin Email. - Go to myaccount.google.com/apppasswords. Make sure you're using your ADMIN email for steps 3-6.
- Type in the name of the Application (FCC Classroom) and select create.
- Google generates a 16-character password
- Copy that password (not your Gmail password)
- Update
SMTP_PASSin.env.developmentwith the new password.
Running the app
- In the terminal, run
npx prisma migrate reset, and pressyto reset your database. - Run
npm run developandnpx prisma studioto run the project. - Log in with your "Admin" email.
- In prisma studio, set your Admin account's role to
ADMIN.
Testing
- Go to the /admin page
- Type out your TEACHER email address, then press Enter.
- Open an Incognito tab, or a different browser, so you can log into a different account.
- Go to your TEACHER email address and onboard using the link provided. (Use Case: Onboarding a Teacher with a brand new account)
- (Alternative) Open localhost:3001 again and create a Classroom account with your TEACHER email address. Then, repeat step 4. (Use Case: Onboarding a Teacher who already has an account)
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
| Diff | Package | Supply Chain Security |
Vulnerability | Quality | Maintenance | License |
|---|---|---|---|---|---|---|
| nodemailer@6.10.1 |
I added test coverage for both asks:
- tests/api/teacherInvites.test.js covers every status branch on accept/resend/revoke: PENDING (valid + expired), already-ACCEPTED (by self and by a different user), and REVOKED/CANCELLED/EXPIRED rejection — plus the ADMIN-stays-ADMIN vs everyone-else-becomes-TEACHER role promotion behavior on accept.
- tests/utils/inviteApiUtils.test.js covers the normalization checking for what a valid email is.
- tests/pages/classes.test.js covers the /classes access gate: signed-out, non-TEACHER role (covers never-invited, revoked-before-accepting, and demoted-after-being-a-teacher, since the gate only checks current role), ADMIN redirect, and successful TEACHER access.
All mocked (Prisma, session, email) — no real DB/SMTP in the test run.
Hi @utsab it's ready for a re-review when you are available!