Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' of https://github.com/LeHuth/mmt-backend into #18-…
Browse files Browse the repository at this point in the history
…Implement-Ticket-Endpoint
  • Loading branch information
sophiacorell committed May 10, 2023
2 parents 0e50576 + 160fba6 commit 7ba5cb0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/endpoints/User/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Request, Response } from 'express';
import jwt from 'jsonwebtoken';
import bcrypt from "bcryptjs"
import UserModel from './UserModel';
import * as process from "process";

const registration = async (req: Request, res: Response) => {
const { username, email, password, isAdmin, isOrganizer } = req.body;
Expand All @@ -13,7 +14,7 @@ const registration = async (req: Request, res: Response) => {

//prüfen ob daten korrekt
//TODO: expresss-validator nutzen
const validEmail: RegExp = /^[\w.-]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,}$/i;
const validEmail = /^[\w.-]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,}$/i;
if(!validEmail.test(email)){
return res.status(400).json({ message: "Invalid Email address" });
}
Expand Down Expand Up @@ -65,8 +66,11 @@ const login = async (req: Request, res: Response) => {
}
};

if(!process.env.JWT_SECRET){
return res.status(500).json({ msg: 'Server error' });
}
try {
const token = jwt.sign(payload, process.env.JWT_SECRET!, { expiresIn: '1h' });
const token = jwt.sign(payload, process.env.JWT_SECRET , { expiresIn: '1h' });
res.json({
token,
user: {
Expand Down

0 comments on commit 7ba5cb0

Please sign in to comment.