-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create endpoint and update contract to activate user
- Loading branch information
Showing
10 changed files
with
95 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { PassportStrategy } from '@nestjs/passport'; | ||
import { Injectable, UnauthorizedException } from '@nestjs/common'; | ||
import { ExtractJwt, Strategy } from 'passport-jwt'; | ||
import { UsersService } from '@api/modules/users/users.service'; | ||
import { ApiConfigService } from '@api/modules/config/app-config.service'; | ||
import { TOKEN_TYPE_ENUM } from '@shared/schemas/auth/token-type.schema'; | ||
|
||
export type JwtPayload = { id: string }; | ||
|
||
export const SignUp = 'sign-up'; | ||
|
||
@Injectable() | ||
export class SignUpStrategy extends PassportStrategy(Strategy, SignUp) { | ||
constructor( | ||
private readonly userService: UsersService, | ||
private readonly config: ApiConfigService, | ||
) { | ||
const { secret } = config.getJWTConfigByType(TOKEN_TYPE_ENUM.SIGN_UP); | ||
super({ | ||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), | ||
secretOrKey: secret, | ||
}); | ||
} | ||
|
||
async validate(payload: JwtPayload) { | ||
const { id } = payload; | ||
const user = await this.userService.findOneBy(id); | ||
if (!user) { | ||
throw new UnauthorizedException(); | ||
} | ||
return user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { z } from "zod"; | ||
import { CreateUserSchema } from "@shared/schemas/users/create-user.schema"; | ||
|
||
export const SignUpSchema = z.object({ | ||
password: z | ||
.string({ message: "Password is required" }) | ||
.min(1, "Password is required") | ||
.min(8, "Password must be more than 8 characters") | ||
.max(32, "Password must be less than 32 characters"), | ||
newPassword: z | ||
.string({ message: "Password is required" }) | ||
.min(1, "Password is required") | ||
.min(8, "Password must be more than 8 characters") | ||
.max(32, "Password must be less than 32 characters"), | ||
}); | ||
|
||
export type SignUpDto = z.infer<typeof SignUpSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters