NPM update, removed CRUD functions from object repository, added prettier

This commit is contained in:
2024-07-22 01:36:05 +02:00
parent 792abdfaf6
commit 6131a8455a
51 changed files with 1450 additions and 1460 deletions

View File

@ -1,37 +1,36 @@
// socket io jwt auth middleware
import { verify } from 'jsonwebtoken';
import { TSocket } from '../utilities/Types';
import config from "../utilities/Config";
import UserRepository from "../repositories/UserRepository";
import {User} from "@prisma/client";
import { verify } from 'jsonwebtoken'
import { TSocket } from '../utilities/Types'
import config from '../utilities/Config'
import UserRepository from '../repositories/UserRepository'
import { User } from '@prisma/client'
export async function Authentication (socket: TSocket, next: any)
{
if (!socket.request.headers.cookie) {
console.log('No cookie provided');
return next(new Error('Authentication error'));
}
export async function Authentication(socket: TSocket, next: any) {
if (!socket.request.headers.cookie) {
console.log('No cookie provided')
return next(new Error('Authentication error'))
}
const cookies = socket.request.headers.cookie.split('; ').reduce((prev: any, current: any) => {
const [name, value] = current.split('=');
prev[name] = value;
return prev;
}, {});
const cookies = socket.request.headers.cookie.split('; ').reduce((prev: any, current: any) => {
const [name, value] = current.split('=')
prev[name] = value
return prev
}, {})
const token = cookies['token'];
const token = cookies['token']
if (token) {
verify(token, config.JWT_SECRET, async (err: any, decoded: any) => {
if (err) {
console.log('err');
return next(new Error('Authentication error'));
}
if (token) {
verify(token, config.JWT_SECRET, async (err: any, decoded: any) => {
if (err) {
console.log('err')
return next(new Error('Authentication error'))
}
socket.user = await UserRepository.getById(decoded.id) as User;
next();
});
} else {
console.log('No token provided');
next(new Error('Authentication error'));
}
}
socket.user = (await UserRepository.getById(decoded.id)) as User
next()
})
} else {
console.log('No token provided')
next(new Error('Authentication error'))
}
}