Comments (3)
Do you mean in the request from the front-end? This feature use express-jwt under the hood so the JWT is used as a bearer token: headers: { 'Authorization':
Basic ${token} }
from overnight.
I tried both Basic ${token}
and Bearer ${token}
and both comes 401. I generated token with JwtManager.jwt({bla-bla}), have set up env variables
OVERNIGHT_JWT_SECRET="string as long as my life"
OVERNIGHT_JWT_EXP="7 days"
I have issue with validate
endpoint, login
works well.
this is my file
import {Request, Response} from 'express';
import {ClassMiddleware, Controller, Get, Middleware, Post, Put} from '@overnightjs/core';
import {Logger} from '@overnightjs/logger';
import {User} from "../models/user";
import {IUser} from "../interfaces/IUser";
import {BAD_CREDENTIALS, FORM_NOT_VALID, INTERNAL_SERVER_ERROR, NOT_IMPLEMENTED, RECAPTCHA_ERROR} from "../const/error";
import {Validators} from "../services/validators";
import {JwtManager} from "@overnightjs/jwt";
import {validateRecaptcha} from "../services/recaptcha";
import {hashPassword} from "../services/database-helpers";
import {CORS} from "../services/CORS";
import * as dotenv from "dotenv";
dotenv.config();
@Controller('user')
@ClassMiddleware(CORS)
export class UserController {
@Get('validate')
@Middleware(JwtManager.middleware)
private validateUser(req: Request, res: Response) {
res.sendStatus(200)
// .header('Access-Control-Allow-Headers:Origin,X-Requested-With,Content-Type,Accept')
// .header('Access-Control-Allow-Methods: GET,POST,PUT,DELETE')
// .header('Access-Control-Allow-Origin: http://localhost:3000');
}
@Post('login')
private async loginUser(req: Request, res: Response) {
const password = hashPassword(req.body.password);
const user: IUser = (await User.findOne({login: req.body.login, password}) as any)
await validateRecaptcha(req.body.token)
.catch(err => {
Logger.Err(err);
res.status(400).json({error: RECAPTCHA_ERROR});
throw new Error(RECAPTCHA_ERROR);
});
if (!user) {
Logger.Warn(req.body);
res.status(401).json({error: BAD_CREDENTIALS});
throw new Error(BAD_CREDENTIALS);
}
const token = JwtManager.jwt({login: user.login, email: user.email, password: user.password});
Logger.Info(req.params.msg);
delete user.password;
return res.status(200).json({login: user.login, email: user.email, token});
}
}
from overnight.
I am sorry, currently it's one issue in my frontend. I'll resolve it and then return
from overnight.
Related Issues (20)
- 404 status on every route
- Overnightjs not generating sourcemap at all
- Question: TypeScript Configuration / getOwnMetadata() returns undefined HOT 7
- AddControllers not working HOT 9
- Unable to access "this" inside controllers HOT 5
- 'Server' no longer exported HOT 2
- Why not async-wrap everything by default? HOT 2
- IRouter error when build HOT 1
- JWT Middleware HOT 1
- 404 on all routes when using express-promise-router HOT 4
- Non-blocking file logging HOT 1
- Problem with @ClassErrorMiddleware HOT 2
- Help wanted: Setting up controllers: {ControllerName} HOT 3
- How to get type safe on req.params HOT 1
- overnight breaks when controllers and server are in separate projects.
- Not an issue: Thank you for this project HOT 1
- OvernightJS controllers cannot be extended
- Controller with multiple enpoint
- Is this repository deprecated? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from overnight.