Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8e934cd

Browse files
committed
updated
1 parentf6b7058 commit8e934cd

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

‎packages/server/src/controllers/auth.controller.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import{TRPCError}from'@trpc/server';
22
import{CookieOptions}from'express';
3-
import{serialize}from'cookie';
43
import{Context}from'../app';
54
importcustomConfigfrom'../config/default';
65
import{CreateUserInput,LoginUserInput}from'../schema/user.schema';
@@ -13,22 +12,23 @@ import {
1312
importredisClientfrom'../utils/connectRedis';
1413
import{signJwt,verifyJwt}from'../utils/jwt';
1514

16-
// Exclude this fields from the response
17-
exportconstexcludedFields=['password'];
15+
constcookieOptions:CookieOptions={
16+
httpOnly:true,
17+
secure:process.env.NODE_ENV==='production',
18+
sameSite:'lax',
19+
};
1820

1921
// Cookie options
2022
constaccessTokenCookieOptions:CookieOptions={
23+
...cookieOptions,
2124
expires:newDate(Date.now()+customConfig.accessTokenExpiresIn*60*1000),
22-
httpOnly:true,
23-
sameSite:'lax',
2425
};
2526

2627
constrefreshTokenCookieOptions:CookieOptions={
28+
...cookieOptions,
2729
expires:newDate(
2830
Date.now()+customConfig.refreshTokenExpiresIn*60*1000
2931
),
30-
httpOnly:true,
31-
sameSite:'lax',
3232
};
3333

3434
// Only set secure to true in production
@@ -45,6 +45,7 @@ export const registerHandler = async ({
4545
email:input.email,
4646
name:input.name,
4747
password:input.password,
48+
photo:input.photo,
4849
});
4950

5051
return{

‎packages/server/src/models/user.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export class User {
3737
@prop({default:'user'})
3838
role:string;
3939

40+
@prop({required:true})
41+
photo:string;
42+
4043
// Instance method to check if passwords match
4144
asynccomparePasswords(hashedPassword:string,candidatePassword:string){
4245
returnawaitbcrypt.compare(candidatePassword,hashedPassword);

‎packages/server/src/schema/user.schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { object, string, TypeOf } from 'zod';
33
exportconstcreateUserSchema=object({
44
name:string({required_error:'Name is required'}),
55
email:string({required_error:'Email is required'}).email('Invalid email'),
6+
photo:string({required_error:'Photo is required'}),
67
password:string({required_error:'Password is required'})
78
.min(8,'Password must be more than 8 characters')
89
.max(32,'Password must be less than 32 characters'),

‎packages/server/src/services/user.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import{omit}from'lodash';
22
import{FilterQuery,QueryOptions}from'mongoose';
33
importuserModel,{User}from'../models/user.model';
4-
import{excludedFields}from'../controllers/auth.controller';
54
import{signJwt}from'../utils/jwt';
65
importredisClientfrom'../utils/connectRedis';
76
import{DocumentType}from'@typegoose/typegoose';
87
importcustomConfigfrom'../config/default';
98

9+
// Exclude this fields from the response
10+
exportconstexcludedFields=['password'];
11+
1012
// CreateUser service
1113
exportconstcreateUser=async(input:Partial<User>)=>{
1214
constuser=awaituserModel.create(input);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp