feat(modules/auth): semi-intergation of auth module#12
feat(modules/auth): semi-intergation of auth module#12itssimmons wants to merge 11 commits intomainfrom
Conversation
|
🚀 Preview deployed: https://api-preview-12-nnratsflva-uc.a.run.app |
There was a problem hiding this comment.
Pull request overview
This PR starts integrating authentication into the Fastify app by adding JWT request guarding, signup/login/refresh/revoke endpoints, early Google OAuth handlers, shared auth-related types, and supporting Prisma/i18n/container configuration updates. It fits into the codebase as the first pass at wiring the modules/auth module into the versioned API and runtime bootstrap.
Changes:
- Added JWT/session handling, signup/login/refresh/revoke controller logic, and auth route registration under
/1/auth. - Introduced early Google OAuth flow pieces, new auth schemas/models/types, and shared exception classes.
- Updated Prisma schema, i18n namespaces/locales, Docker compose/dev container setup, and package dependencies to support auth work.
Reviewed changes
Copilot reviewed 36 out of 42 changed files in this pull request and generated 24 comments.
Show a summary per file
| File | Description |
|---|---|
plugins/zod.ts |
Added a placeholder Fastify plugin intended for request validation/localization work. |
plugins/jwt.ts |
Added a global JWT pre-handler that populates req.user from Redis-backed sessions. |
plugins/i18n.ts |
Exposed language alongside t() on Fastify requests. |
package.json |
Added auth/OAuth dependencies and bcrypt typings. |
modules/users/models/User.d.ts |
Added a lightweight shared user interface for session/auth typing. |
modules/users/controllers/index.controller.ts |
Added a commented-out placeholder controller scaffold for user features. |
modules/auth/types/jwt.d.ts |
Reshaped JWT subject/payload typings for access/refresh tokens. |
modules/auth/serivces/jwt.service.ts |
Added token creation helper for access/refresh JWT issuance. |
modules/auth/serivces/google.service.ts |
Added an empty Google OAuth service namespace placeholder. |
modules/auth/schemas/signup.schema.ts |
Added signup body validation with nickname rules. |
modules/auth/schemas/signin.schema.ts |
Added a sign-in schema definition. |
modules/auth/schemas/refresh-token.schema.ts |
Switched refresh-token schema to a named export. |
modules/auth/schemas/index.schema.ts |
Added barrel exports for auth schemas. |
modules/auth/schemas/google-user.schema.ts |
Added schema for Google user profile payloads. |
modules/auth/schemas/credential.schema.ts |
Reworked login credential validation to accept email or nickname. |
modules/auth/routes/index.router.ts |
Expanded auth routes to include signup, Google OAuth, and HTTP verb changes. |
modules/auth/models/Session.d.ts |
Added session shape stored in Redis. |
modules/auth/models/Auth.d.ts |
No visible diff was provided; appears to be an empty/placeholder file. |
modules/auth/exceptions/unauthorized.exception.ts |
Removed module-local unauthorized exception in favor of shared exceptions. |
modules/auth/exceptions/notfound.exception.ts |
Removed module-local not-found exception in favor of shared exceptions. |
modules/auth/controllers/index.controller.ts |
Replaced stub auth flows with Prisma/bcrypt/Redis-backed signup, login, logout, refresh, and revoke handlers. |
modules/auth/controllers/google-oauth.controller.ts |
Added Google OAuth URL generation and callback handling with user/session creation. |
locales/pt-BR/zod.json |
Added Zod namespace file for Portuguese translations. |
locales/fr-FR/zod.json |
Added Zod namespace file for French translations. |
locales/es-ES/zod.json |
Added Spanish translation for nickname validation rules. |
locales/es-ES/errors.json |
Added a new Spanish auth-related error string. |
locales/en-US/zod.json |
Added English translation for nickname validation rules. |
index.ts |
Registered JWT plugin globally and added verbose request logging on /echo. |
exceptions/unauthorized.exception.ts |
Added shared unauthorized exception class with status code. |
exceptions/notfound.exception.ts |
Added shared not-found exception class with status code. |
exceptions/index.exception.ts |
Added barrel export for shared exceptions. |
exceptions/conflict.exception.ts |
Added shared conflict exception class with status code. |
database/redis/client.ts |
Renamed Redis config variables and client export for clarity. |
database/prisma/schema.prisma |
Extended auth-related schema with nullable OAuth links, metadata, relations, and new providers. |
database/prisma/migrations/20260502151239/migration.sql |
Added migration to make OAuth account user links nullable and add FK behavior. |
database/prisma/migrations/20260502141005/migration.sql |
Added migration for new OAuth enum values and provider metadata/avatar nullability. |
config/i18n.ts |
Added zod namespace and typed the i18n config shape. |
compose.yml |
Added a dev compose stack for API, Postgres, and Redis. |
ci/Dockerfile.dev |
Added a development Dockerfile for Bun/Prisma. |
bun.lock |
Updated lockfile for new dependencies. |
@types/i18next.d.ts |
Added a minimal ambient i18next.TFunction type. |
.env.example |
Reworked env template toward explicit Postgres/Redis variables. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… refresh token Agent-Logs-Url: https://github.com/dojoh-dev/api/sessions/e51ba94d-b8f5-4c51-8fb6-1f6c2da7b64f Co-authored-by: itssimmons <62354548+itssimmons@users.noreply.github.com>
…on native login Agent-Logs-Url: https://github.com/dojoh-dev/api/sessions/f56905a4-f168-4cf2-9242-dd5ea3a6ad28 Co-authored-by: itssimmons <62354548+itssimmons@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 41 out of 48 changed files in this pull request and generated 25 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🚀 Preview deployed: https://api-preview-12-nnratsflva-uc.a.run.app |
Agent-Logs-Url: https://github.com/dojoh-dev/api/sessions/2b746871-9486-4932-89f8-036a9433bb65 Co-authored-by: itssimmons <62354548+itssimmons@users.noreply.github.com>
|
🚀 Preview deployed: https://api-preview-12-nnratsflva-uc.a.run.app |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 41 out of 48 changed files in this pull request and generated 14 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const { tokens } = await oauth2Client.getToken(code); | ||
| oauth2Client.setCredentials(tokens); | ||
|
|
||
| const oauth2 = google.oauth2({ | ||
| auth: oauth2Client, | ||
| version: "v2", | ||
| }); | ||
|
|
||
| const { data } = await oauth2.userinfo.get(); |
| const user = await prisma.user.upsert({ | ||
| where: { | ||
| email: discordUser.email, | ||
| }, | ||
| update: { | ||
| // Do nothing, we don't want to overwrite existing user data | ||
| }, | ||
| create: { | ||
| email: discordUser.email || "", |
| create: { | ||
| email: githubUser.email ?? "", | ||
| nickname: githubUser.login, |
| create: { | ||
| email: googleUser.email, | ||
| nickname: googleUsername, |
|
|
||
| GITHUB_CLIENT_ID= | ||
| GITHUB_CLIENT_SECRET= | ||
| GITHUB_REDIRECT_URI=https://example.com/auth/google/callback |
|
|
||
| DISCORD_CLIENT_ID= | ||
| DISCORD_CLIENT_SECRET= | ||
| DISCORD_REDIRECT_URI=https://example.com/auth/github/callback |
| reply.setCookie("oauth_state", state, { | ||
| httpOnly: true, | ||
| secure: true, | ||
| sameSite: "lax", | ||
| maxAge: 60 * 5, // 5m |
| return reply.status(400).send("Discord user ID not found"); | ||
| } | ||
|
|
||
| const discordEmail = |
| return reply.redirect(authorizationUrl); | ||
| }, | ||
| oneTap: async (req: FastifyRequest, reply: FastifyReply) => { | ||
| const { credential } = req.body as { |
|
🚀 Preview deployed: https://api-preview-12-nnratsflva-uc.a.run.app |
|
Closing because it got way too messy |
|
🧹 Preview no longer available |
Pull Request Template
📌 Description
Provide a clear and concise description of what this PR does.
🔧 Type of Change
Select all that apply:
🧪 How Has This Been Tested?
Describe the testing strategy:
Steps to reproduce/test:
1.
2.
3.
📂 Related Issues
Link any related issues:
If yes, describe the impact and migration steps:
📸 Screenshots / Logs (if applicable)
Add screenshots, request/response examples, or logs if helpful.
✅ Checklist
Ensure your PR meets the following:
💬 Additional Notes
Anything else reviewers should know.