Skip to content

Instantly share code, notes, and snippets.

@seanpmaxwell
Last active May 18, 2019 14:45
Show Gist options
  • Save seanpmaxwell/2cc9328ffabf23f52833eedb98acc167 to your computer and use it in GitHub Desktop.
Save seanpmaxwell/2cc9328ffabf23f52833eedb98acc167 to your computer and use it in GitHub Desktop.
import { Controller, Middleware, Get } from '@overnightjs/core'
import { jwt, jwtmiddleware, SecureRequest } from '@overnightjs/jwt'
import { Request, Response } from 'express'
import { ParentController } from './ParentController'
@Controller('api/jwt')
export class UserController extends ParentController {
@Get('getjwt/:email')
private getJwt(req: Request, res: Response): void {
let jwtStr = jwt({
email: req.params.email
});
res.status(200).json({jwt: jwtStr});
}
@Get('callProtectedRoute')
@Middleware(jwtmiddleware)
private callProtectedRoute(req: SecureRequest, res: Response): void {
res.status(200).json({email: req.payload.email});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment