cleanup organizing and stuff

This commit is contained in:
talksik
2022-06-08 05:44:29 -05:00
parent 7aab1ee26c
commit e397ac6bb8
9 changed files with 51 additions and 3 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"ignore": ["**/*.test.ts", "**/*.spec.ts", "node_modules"],
"watch": ["./", "../core"],
"watch": ["./src", "../core"],
"exec": "npm run start:dev",
"ext": "ts"
}
+2 -1
View File
@@ -6,7 +6,7 @@
"scripts": {
"core": "rm -rf ./core && cp -r ../core/src ./core/",
"dev": "NODE_ENV=development nodemon",
"start:dev": "ts-node index.ts",
"start:dev": "ts-node ./src/index.ts",
"lint": "eslint --ext .ts,.tsx .",
"build": "npm run lint && tsc -p .",
"start": "node dist/index.js",
@@ -26,6 +26,7 @@
"dependencies": {
"@sentry/node": "^7.0.0",
"@sentry/tracing": "^7.0.0",
"@types/jsonwebtoken": "^8.5.8",
"axios": "^0.26.1",
"cors": "^2.8.5",
"express": "^4.17.3",
@@ -7,6 +7,7 @@ import * as Tracing from '@sentry/tracing';
import express, { Application, NextFunction, Request, Response } from 'express';
import InitializeWs from './services/SocketService';
import NirvanaResponse from '@nirvana/core/responses/nirvanaResponse';
import cors from 'cors';
import morgan from 'morgan';
@@ -23,7 +24,7 @@ app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
res.status(500);
res.render('error', { error: err });
res.json(new NirvanaResponse(undefined, err, err.message));
});
app.get('/', (req: Request, res: Response) => {
+36
View File
@@ -0,0 +1,36 @@
import { NextFunction, Request, Response } from 'express';
// eslint-disable-next-line @typescript-eslint/no-var-requires
import jwt, { JwtPayload } from 'jsonwebtoken';
import environmentVariables from '../config/config';
// used by specific routes that need to authentication
export const authCheck = async (req: Request, res: Response, next: NextFunction) => {
try {
const { authorization } = req.headers;
if (!authorization) {
throw Error('No provided header');
}
// verify jwt token with our api secret
const decoded: string | JwtPayload = jwt.verify(
authorization,
environmentVariables.JWT_TOKEN_SECRET,
);
res.locals.userInfo = decoded as JwtClaims;
next();
} catch (error) {
res.status(401).send('unauthorized');
}
};
export interface JwtClaims {
userId: string;
googleUserId: string;
picture: string;
email: string;
name: string;
}
@@ -1,3 +1,5 @@
import { JwtClaims } from '../middleware/auth';
export default function InitializeWs(io: any) {
console.log('initializing web sockets');
@@ -22,5 +24,6 @@ export default function InitializeWs(io: any) {
})
.on('connection', (socket: any) => {
console.log(`connected`, socket.id);
const userInfo: JwtClaims = socket.userInfo;
});
}
+7
View File
@@ -1398,6 +1398,13 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==
"@types/jsonwebtoken@^8.5.8":
version "8.5.8"
resolved "https://registry.yarnpkg.com/@types/jsonwebtoken/-/jsonwebtoken-8.5.8.tgz#01b39711eb844777b7af1d1f2b4cf22fda1c0c44"
integrity sha512-zm6xBQpFDIDM6o9r6HSgDeIcLy82TKWctCXEPbJJcXb5AKmi5BNNdLXneixK4lplX3PqIVcwLBCGE/kAGnlD4A==
dependencies:
"@types/node" "*"
"@types/keyv@*":
version "3.1.4"
resolved "https://registry.yarnpkg.com/@types/keyv/-/keyv-3.1.4.tgz#3ccdb1c6751b0c7e52300bcdacd5bcbf8faa75b6"