summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/app.controller.ts8
-rw-r--r--server/console.ts39
-rw-r--r--server/controllers/sessions.controller.ts14
-rw-r--r--server/dto/sign_in.dto.ts2
-rw-r--r--server/providers/services/users.service.ts2
5 files changed, 58 insertions, 7 deletions
diff --git a/server/app.controller.ts b/server/app.controller.ts
index a6bcf58..685cf8f 100644
--- a/server/app.controller.ts
+++ b/server/app.controller.ts
@@ -1,8 +1,12 @@
-import { Controller, Get, Render } from '@nestjs/common';
+import { Controller, Get, Render, Req } from '@nestjs/common';
+import { Request } from 'express';
@Controller()
export class AppController {
@Get()
@Render('index')
- index() {}
+ index(@Req() req: Request) {
+ const jwt = req.cookies['_token'];
+ return { jwt };
+ }
}
diff --git a/server/console.ts b/server/console.ts
new file mode 100644
index 0000000..485789a
--- /dev/null
+++ b/server/console.ts
@@ -0,0 +1,39 @@
+import 'dotenv/config';
+import { NestFactory } from '@nestjs/core';
+import * as repl from 'repl';
+import * as Logger from 'purdy';
+
+const LOGGER_OPTIONS = {
+ indent: 2,
+ depth: 1,
+};
+
+class InteractiveNestJS {
+ async run() {
+ // create the application context
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
+ const targetModule = require(`${__dirname}/app.module`);
+ const applicationContext = await NestFactory.createApplicationContext(
+ // tslint:disable-next-line: no-string-literal
+ targetModule['AppModule'],
+ );
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
+ const awaitOutside = require('await-outside');
+ // start node repl
+ const server = repl.start({
+ useColors: true,
+ prompt: '> ',
+ writer: replWriter,
+ ignoreUndefined: true,
+ });
+ server.context.app = applicationContext;
+ awaitOutside.addAwaitOutsideToReplServer(server);
+ }
+}
+
+function replWriter(value: any): string {
+ return Logger.stringify(value, LOGGER_OPTIONS);
+}
+
+const session = new InteractiveNestJS();
+session.run();
diff --git a/server/controllers/sessions.controller.ts b/server/controllers/sessions.controller.ts
index 3b179ad..90b8e78 100644
--- a/server/controllers/sessions.controller.ts
+++ b/server/controllers/sessions.controller.ts
@@ -1,9 +1,11 @@
import {
Body,
Controller,
+ Delete,
HttpException,
HttpStatus,
Post,
+ Redirect,
Res,
} from '@nestjs/common';
import { Response } from 'express';
@@ -18,13 +20,13 @@ import { SignInDto } from 'server/dto/sign_in.dto';
export class SessionsController {
constructor(private usersService: UsersService) {}
- @Post('/sign_in')
- async signIn(
+ @Post('/sessions')
+ async create(
@Body() body: SignInDto,
@Res({ passthrough: true }) res: Response,
) {
const { verified, user } = await this.usersService.verify(
- body.username,
+ body.email,
body.password,
);
@@ -45,4 +47,10 @@ export class SessionsController {
res.cookie('_token', token);
return { token };
}
+
+ @Delete('/sessions')
+ async destroy(@Res({ passthrough: true }) res: Response) {
+ res.clearCookie('_token');
+ return { success: true };
+ }
}
diff --git a/server/dto/sign_in.dto.ts b/server/dto/sign_in.dto.ts
index f480c43..0671602 100644
--- a/server/dto/sign_in.dto.ts
+++ b/server/dto/sign_in.dto.ts
@@ -1,4 +1,4 @@
export class SignInDto {
- username: string;
+ email: string;
password: string;
}
diff --git a/server/providers/services/users.service.ts b/server/providers/services/users.service.ts
index 0f502b2..21438a4 100644
--- a/server/providers/services/users.service.ts
+++ b/server/providers/services/users.service.ts
@@ -30,6 +30,6 @@ export class UsersService {
password,
user.password_hash,
);
- return { verified, user };
+ return { verified, user: verified ? user : null };
}
}