import { Request , Response , NextFunction } from 'express' ; import { get , controller , use } from './decorators' ; function requireAuth ( req , res , next ) { if ( req . session && req . session . loggedIn ) { next ( ) ; return ; } res . status ( 403 ) ; res . send ( 'Not permitted' ) ; } @ controller ( '' ) class RootController { @ get ( '/' ) getRoot ( req , res ) { if ( req . session && req . session . loggedIn ) { res . send ( `
        <div>
          <div>You are logged in</div>
          <a href="/auth/logout">Logout</a>
        </div>
      ` ) ; } else { res . send ( `
        <div>
          <div>You are not logged in</div>
          <a href="/auth/login">Login</a>
        </div>
      ` ) ; } } @ get ( '/protected' ) @ use ( requireAuth ) getProtected ( req , res ) { res . send ( 'Welcome to protected route, logged in user' ) ; } }