Skip to content

uploaded mail login logic - #4

Open
DariaDrob wants to merge 2 commits into
developfrom
feature/mail-link-auth
Open

DariaDrob wants to merge 2 commits into
developfrom
feature/mail-link-auth

Conversation

@DariaDrob

Copy link
Copy Markdown

Auth Module

Added AuthModule (auth.service.ts, auth.controller.ts, DTOs: send-link.dto.ts, verify-token-response.dto.ts).

Endpoints:

POST /auth/send-link — accepts { email: string }, stores user and token, sends a magic link.

GET /auth/verify?token=...&email=... — validates token, returns JWT or an error if expired.

Transactions added for creating/updating User and LoginToken.

Email validation via EMAIL_REGEX.

Database

Added entities: user.entity.ts, login-token.entity.ts.

Added migration AuthMigration-20251007122300.ts for users and login_tokens tables with indexes and foreign keys.

Updated example-global.entities.ts, database.config.js, typeorm.config.js.

Email

Configured Nodemailer with Gmail SMTP using .env (EMAIL_HOST, EMAIL_USER, EMAIL_PASSWORD).

Magic link built from FRONTEND_URL and UPLOAD_PATH in .env.

Swagger

Added documentation for /auth/send-link and /auth/verify with examples and error descriptions.

Dependencies

Installed nodemailer, uuid, @nestjs/jwt, class-transformer, and related types.

Working Functionality

Backend starts via npm run start:dev with no TypeScript errors.

Swagger available at http://localhost:3000/api/docs.

POST /auth/send-link:

saves email and token to DB,

sends email with valid link (e.g., http://localhost:5173/upload?token=...&email=...).

GET /auth/verify:

returns JWT if token is valid,

deletes token after verification,

returns 401 if expired.

Verified DB records in MySQL Workbench — data stored correctly.
esting

Backend launched with npm run start:dev.

Tested via Postman:

POST /auth/send-link with {email } — email successfully sent, data stored in DB;
Next Steps:

add POST request to /auth/send-link in useExampleWorkForm.ts;

implement /upload page with GET /auth/verify handling;

@DariaDrob
DariaDrob requested a review from lyudad October 8, 2025 16:08
synchronize: true,
entities: globalEntities,
migrations: ['@src/database/migrations/*.ts', '@dist/database/migrations/*.js'],
})); No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better add evs validation, and show to user that he need to add env, instead of setup the default value

@ApiOperation({ summary: 'Send magic link to email' })
@ApiResponse({ status: 200, description: 'Magic link sent', type: Object })
@ApiResponse({ status: 400, description: 'Invalid email' })
async sendMagicLink(@Body() body: SendLinkDto) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.1.1

@ApiOperation({ summary: 'Verify magic link token' })
@ApiResponse({ status: 200, description: 'Token verified', type: VerifyTokenResponseDto })
@ApiResponse({ status: 401, description: 'Expired or invalid token' })
async verifyToken(@Query('token') token: string, @Query('email') email: string) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.1.1

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.

2 participants