Skip to content

Commit 1afae20

Browse files
committed
refactor: auth module
1 parent a42d94a commit 1afae20

18 files changed

Lines changed: 158 additions & 148 deletions

packages/apps/reputation-oracle/server/src/config/auth-config.service.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,47 @@ export class AuthConfigService {
2222
}
2323

2424
/**
25-
* The expiration time (in seconds) for access tokens.
26-
* Default: 600
25+
* The expiration time (in ms) for access tokens.
26+
* Default: 600000
2727
*/
2828
get accessTokenExpiresIn(): number {
29-
return +this.configService.get<number>('JWT_ACCESS_TOKEN_EXPIRES_IN', 600);
29+
return (
30+
+this.configService.get<number>('JWT_ACCESS_TOKEN_EXPIRES_IN', 600) * 1000
31+
);
3032
}
3133

3234
/**
33-
* The expiration time (in seconds) for refresh tokens.
34-
* Default: 3600
35+
* The expiration time (in ms) for refresh tokens.
36+
* Default: 3600000
3537
*/
3638
get refreshTokenExpiresIn(): number {
37-
return +this.configService.get<number>(
38-
'JWT_REFRESH_TOKEN_EXPIRES_IN',
39-
3600,
39+
return (
40+
+this.configService.get<number>('JWT_REFRESH_TOKEN_EXPIRES_IN', 3600) *
41+
1000
4042
);
4143
}
4244

4345
/**
44-
* The expiration time (in seconds) for email verification tokens.
45-
* Default: 86400
46+
* The expiration time (in ms) for email verification tokens.
47+
* Default: 86400000
4648
*/
4749
get verifyEmailTokenExpiresIn(): number {
48-
return +this.configService.get<number>(
49-
'VERIFY_EMAIL_TOKEN_EXPIRES_IN',
50-
86400,
50+
return (
51+
+this.configService.get<number>('VERIFY_EMAIL_TOKEN_EXPIRES_IN', 86400) *
52+
1000
5153
);
5254
}
5355

5456
/**
55-
* The expiration time (in seconds) for forgot password tokens.
56-
* Default: 86400
57+
* The expiration time (in ms) for forgot password tokens.
58+
* Default: 86400000
5759
*/
5860
get forgotPasswordExpiresIn(): number {
59-
return +this.configService.get<number>(
60-
'FORGOT_PASSWORD_TOKEN_EXPIRES_IN',
61-
86400,
61+
return (
62+
+this.configService.get<number>(
63+
'FORGOT_PASSWORD_TOKEN_EXPIRES_IN',
64+
86400,
65+
) * 1000
6266
);
6367
}
6468

packages/apps/reputation-oracle/server/src/modules/auth/auth.controller.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class AuthController {
6464
@Post('/web2/signup')
6565
@HttpCode(200)
6666
async signup(@Body() data: Web2SignUpDto): Promise<void> {
67-
await this.authService.signup(data);
67+
await this.authService.signup(data.email, data.password);
6868
}
6969

7070
@ApiOperation({
@@ -85,7 +85,10 @@ export class AuthController {
8585
@Post('/web3/signup')
8686
@HttpCode(200)
8787
async web3SignUp(@Body() data: Web3SignUpDto): Promise<SuccessAuthDto> {
88-
const authTokens = await this.authService.web3Signup(data);
88+
const authTokens = await this.authService.web3Signup(
89+
data.signature,
90+
data.address,
91+
);
8992
return authTokens;
9093
}
9194

@@ -104,7 +107,7 @@ export class AuthController {
104107
@Post('/web2/signin')
105108
@HttpCode(200)
106109
async signin(@Body() data: Web2SignInDto): Promise<SuccessAuthDto> {
107-
const authTokens = await this.authService.signin(data);
110+
const authTokens = await this.authService.signin(data.email, data.password);
108111
return authTokens;
109112
}
110113

@@ -122,7 +125,10 @@ export class AuthController {
122125
@Post('/web3/signin')
123126
@HttpCode(200)
124127
async web3SignIn(@Body() data: Web3SignInDto): Promise<SuccessAuthDto> {
125-
const authTokens = await this.authService.web3Signin(data);
128+
const authTokens = await this.authService.web3Signin(
129+
data.address,
130+
data.signature,
131+
);
126132
return authTokens;
127133
}
128134

@@ -140,7 +146,7 @@ export class AuthController {
140146
@Post('/refresh')
141147
@HttpCode(200)
142148
async refreshToken(@Body() data: RefreshDto): Promise<SuccessAuthDto> {
143-
const authTokens = await this.authService.refresh(data);
149+
const authTokens = await this.authService.refresh(data.refreshToken);
144150
return authTokens;
145151
}
146152

@@ -158,7 +164,7 @@ export class AuthController {
158164
@Post('/web2/forgot-password')
159165
@HttpCode(200)
160166
async forgotPassword(@Body() data: ForgotPasswordDto): Promise<void> {
161-
await this.authService.forgotPassword(data);
167+
await this.authService.forgotPassword(data.email);
162168
}
163169

164170
@ApiOperation({
@@ -175,7 +181,7 @@ export class AuthController {
175181
@Post('/web2/restore-password')
176182
@HttpCode(200)
177183
async restorePassword(@Body() data: RestorePasswordDto): Promise<void> {
178-
await this.authService.restorePassword(data);
184+
await this.authService.restorePassword(data.password, data.token);
179185
}
180186

181187
@ApiOperation({
@@ -191,7 +197,7 @@ export class AuthController {
191197
@Post('/web2/verify-email')
192198
@HttpCode(200)
193199
async emailVerification(@Body() data: VerifyEmailDto): Promise<void> {
194-
await this.authService.emailVerification(data);
200+
await this.authService.emailVerification(data.token);
195201
}
196202

197203
@ApiOperation({
@@ -211,7 +217,7 @@ export class AuthController {
211217
@Req() request: RequestWithUser,
212218
@Body() data: ResendVerificationEmailDto,
213219
): Promise<void> {
214-
await this.authService.resendEmailVerification(request.user, data);
220+
await this.authService.resendEmailVerification(request.user, data.email);
215221
}
216222

217223
@ApiOperation({

packages/apps/reputation-oracle/server/src/modules/auth/auth.error.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class AuthError extends BaseError {
1919
}
2020

2121
export class InvalidOperatorSignupDataError extends BaseError {
22-
constructor(public readonly detail: string) {
22+
constructor(readonly detail: string) {
2323
super('Invalid operator signup data');
2424
}
2525
}
@@ -49,15 +49,15 @@ export class InvalidOperatorJobTypesError extends InvalidOperatorSignupDataError
4949
}
5050

5151
export class DuplicatedUserEmailError extends BaseError {
52-
constructor(public readonly email: string) {
52+
constructor(readonly email: string) {
5353
super(
5454
'The email you are trying to use already exists. Please check that the email is correct or use a different email.',
5555
);
5656
}
5757
}
5858

5959
export class DuplicatedUserAddressError extends BaseError {
60-
constructor(public readonly address: string) {
60+
constructor(readonly address: string) {
6161
super(
6262
'The address you are trying to use already exists. Please, use a different address.',
6363
);

0 commit comments

Comments
 (0)