This file contains hidden or 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
import { AuthConfig } from './auth.config'; | |
import { Inject, Injectable } from '@nestjs/common'; | |
import { | |
AuthenticationDetails, | |
CognitoUser, | |
CognitoUserPool, | |
CognitoUserAttribute, | |
} from 'amazon-cognito-identity-js'; | |
@Injectable() |
This file contains hidden or 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
import { BadRequestException, Body, Controller, Post } from '@nestjs/common'; | |
import { AuthService } from './auth.service'; | |
@Controller('auth') | |
export class AuthController { | |
constructor(private readonly authService: AuthService) {} | |
@Post('register') | |
async register( | |
@Body() registerRequest: { name: string; password: string; email: string }, |
This file contains hidden or 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
import { NestFactory } from '@nestjs/core'; | |
import { AppModule } from './app.module'; | |
global['fetch'] = require('node-fetch'); | |
async function bootstrap() { | |
const app = await NestFactory.create(AppModule); | |
await app.listen(3000); | |
} | |
bootstrap(); |
This file contains hidden or 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
import { BadRequestException, Body, Controller, Post } from '@nestjs/common'; | |
import { AuthService } from './auth.service'; | |
@Controller('auth') | |
export class AuthController { | |
constructor(private readonly authService: AuthService) {} | |
@Post('login') | |
async login(@Body() authenticateRequest: { name: string, password: string }) { |
This file contains hidden or 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
import { AuthConfig } from './auth.config'; | |
import { Inject, Injectable } from '@nestjs/common'; | |
import { | |
AuthenticationDetails, | |
CognitoUser, | |
CognitoUserPool, | |
} from 'amazon-cognito-identity-js'; | |
@Injectable() | |
export class AuthService { |
This file contains hidden or 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
import { Module } from '@nestjs/common'; | |
import { AuthService } from './auth.service'; | |
import { AuthConfig } from './auth.config'; | |
@Module({ | |
providers: [AuthService, AuthConfig] | |
}) | |
export class AuthModule {} |
This file contains hidden or 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
COGNITO_USER_POOL_ID=eu-central-1_AadYWQBJE | |
COGNITO_CLIENT_ID=1bk2sqm1453tu5g7ldkg5vk23u | |
COGNITO_REGION=eu-central-1 |
This file contains hidden or 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
import { Module } from '@nestjs/common'; | |
import { AuthModule } from './auth/auth.module'; | |
import { ConfigModule } from '@nestjs/config'; | |
@Module({ | |
imports: [ | |
AuthModule, | |
ConfigModule.forRoot({ | |
isGlobal: true, | |
}), |
This file contains hidden or 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
import { Injectable } from '@nestjs/common'; | |
@Injectable() | |
export class AuthConfig { | |
public userPoolId: string = process.env.COGNITO_USER_POOL_ID; | |
public clientId: string = process.env.COGNITO_CLIENT_ID; | |
public region: string = process.env.COGNITO_REGION; | |
public authority = `https://cognito-idp.${process.env.COGNITO_REGION}.amazonaws.com/${process.env.COGNITO_USER_POOL_ID}`; | |
} |
NewerOlder