본문 바로가기

Node.js18

e2d Testing e2d Testing 2023. 4. 26.
metaData metaData 2023. 4. 26.
Reflector Reflector 2023. 4. 26.
slug 슬러그(Slug)란 원래 신문이나 잡지 등에서 제목을 쓸 때, 중요한 의미를 포함하는 단어만을 이용해 제목을 작성하는 방법을 말합니다. 조사나 전치사 등을 빼고 핵심 의미를 담고 있는 단어를 조합해서 긴 제목을 간단 명료하게 표현하는 것이죠. 많은 기사를 다루어야 하는 신문 등에서 편집하는 방법인 것이죠. 띄어쓰기는 하이픈(-)으로 대체하고, 쉼표나 마침표 등 기호를 자동으로 없애주거나 원하는 형태로 변환. Apple-tv apple tv >> apple-tv Apple TV 이런 3가지 text type을 아래와 같은 형태로 변경하여 같은 text로 묶어 불필요한 분산을 방지. const a = Text_value .trim() .toLowerCase() .replace(/ +/g, ' '); //re.. 2023. 4. 26.
Unit Testing Unit Testing vs End to End Testing - Unit Testing : Unit testing should be conducted independently. 2023. 4. 22.
Email Verification Email 검증 - verification entity - create verifications - verifying user - mailgun - mail module - frontend 작업 전까지는 수동으로 verification 가능. 2023. 4. 22.
One-to-one relations A가 오로지 하나의 B만 포함한다! B역시 오직 하나의 A만 포함한다. https://typeorm.io/one-to-one-relations One-to-one is a relation where A contains only one instance of B, and B contains only one instance of A. Let's take for example User and Profile entities. User can have only a single profile, and a single profile is owned by only a single user. // Profile import { Entity, PrimaryGeneratedColumn, Column } from "typeor.. 2023. 4. 14.
[User] update Profile User의 Profile을 Update! (email & password) // users.resolver.ts ... @UseGuards(AuthGuard) @Mutation((returns) => EditProfileOutput) async editProfile( @AuthUser() authUser: User, @Args('input') editProfileInput: EditProfileInput, ): Promise { try { await this.userService.editProfie(authUser.id, editProfileInput); return { ok: true, }; } catch (error) { return { ok: false, error }; } } ... // user.. 2023. 4. 14.
[User] Authentication #5 AuthUser Decorator login이 되어있지 않다면 request를 멈추게 함. Decorator를 만들어보자~ // auth-user.decorator.ts // custom decorator export const AuthUser = createParamDecorator( (data: unknown, ctx: ExecutionContext) => { const gqlContext = GqlExecutionContext.create(ctx).getContext(); return gqlContext['user']; }, ); // user.resolver.ts ... @Query((returns) => User) @UseGuards(AuthGuard) me(@AuthUser() authUser: User) { return au.. 2023. 4. 8.
[User] Authentication #4 Guard Guard: Request를 다음 단계로 진행할지 말지 결정하는 함수. nest g mo auth 로 auth module 추가 (jwt module에서 더 다룰 건 없다) // auth.guard.ts @Injectable() export class AuthGuard implements CanActivate { // CanActive는 반환되는 값에 따라 ture일 경우 request를 진행시키고 false인 경우 request를 멈추게 한다. canActivate(context: ExecutionContext): boolean { // content가 http로 되어 있어서 graphql context로 변환해줘야 한다. const gqlContext = GqlExecutionContext.creat.. 2023. 4. 8.
[User] Authentication #3 JWT Middleware 사용자에게 전달된 token의 정보를 어떻게 받을 수 있을까? JWT middleware 작성 / 적용 // jwt.middleware.ts @Injectable() export class JwtMiddleware implements NestMiddleware {} // 미들웨어에 추가 // #1 app.module.ts export class AppModule implements NestModule { configure(consumer: MiddlewareConsumer) { consumer .apply(JwtMiddleware) .forRoutes({ path: '/graphql', method: RequestMethod.ALL }); } } path: '*' 전체 route에 적용할 수도 있고, m.. 2023. 4. 8.
[User] Authentication #2 JWT Module 이 방법은 굳이 필요 없고 더 간단한 방법도 있으나 Nestjs의 Module 구조의 이해를 위해 작업해 봄. nest g mo jwt / nest g s jwt 를 통해 module / service 생성 JwtModule이 option을 갖고 활용할 수 있도록 Dynamic Module을 Return 하도록 Module 수정 module에서 service로 어떻게 injection 하는지는 아래와 같다. // jwt.module.ts @Module({}) @Global() // grobal 설정하면 해당 module에서 import 안해도 사용 가능. export class JwtModule { static forRoot(options: JwtModuleOptions): DynamicModule { .. 2023. 4. 7.
[User] Authentication #1 - login login resolver / service / dto nestjs/passports, passports/jwt는 편하고 좋지만 일단 패스. step1. jwt 붙이기 step2. jwt module 만들어서 this.jwt.sign() 으로 사용. > nestjs module 구조 공부 용도. jwt token은 유저가 해독 가능하기 때문에 민감한 정보를 넣지 않고, 일반적으로는 ID 정도의 정보가 적당하다. token에 담을 항목을 정해주고, private key를 적어주면 끝. private key를 통해 변경된 토큰 여부를 확인할 수 있다. https://randomkeygen.com/ 를 통해 쉽게 랜덤 키를 생성할 수 있음. https://jwt.io/ https://ykie-dev.tisto.. 2023. 4. 7.
TypeOrm https://typeorm.io/listeners-and-subscribers Entity Listeners and Subscribers Entity Listeners and Subscribers What is an Entity Listener @AfterLoad @BeforeInsert @AfterInsert @BeforeUpdate @AfterUpdate @BeforeRemove @AfterRemove @BeforeSoftRemove @AfterSoftRemove @BeforeRecover @AfterRecover What is a Subscriber Event Object # What is an Entity Listener Any of your entities can have methods wit.. 2023. 4. 6.
[User] Model #3 Create Account (+ Hashing Password) users.service.ts / users.resolve.ts Password Hashing password를 db에 저장할 때 그대로 저장하지 않는다!! 매우 큰 보안적 위험이 있기 때문에! '123' ➡ hashing ➡ 'xxxxxxxxxxxxxxxxxxxxxxxx' (one way function) ⬅⬅⬅ 이 방향으로 복구 할 수 없다. // user.entity.ts @InputType({ isAbstract: true }) @ObjectType() @Entity() export class User extends CoreEntity { ... @Column() @Field((type) => String) password: string; ... @BeforeInsert() async hashPa.. 2023. 4. 6.
728x90