Last active
November 16, 2020 11:20
-
-
Save DScheglov/26c06f5e3800555a617b3f0c9fb8e2b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createParamDecorator, ExecutionContext, SetMetadata } from '@nestjs/common'; | |
export const Passport = createParamDecorator((data: unknown, ctx: ExecutionContext) => { | |
const req = ctx.switchToHttp().getRequest(); | |
const logIn = <U>(user: U): Promise<U> => new Promise( | |
(resolve, reject) => req.logIn(user, err => err ? reject(err) : resolve(user)) | |
); | |
return { logIn }; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get, UseGuards, Request, UseInterceptors } from '@nestjs/common'; | |
import { SSOAuthGuard } from './sso-auth.guard'; | |
import { AuthService } from './auth.service'; | |
import { LoginInterceptor } from './login.interceptor'; | |
import { User } from '../common/user.decorator'; | |
@Controller('auth') | |
export class AuthController { | |
constructor( | |
private readonly auth: AuthService | |
) { | |
console.log('AuthController created'); | |
} | |
@Get('login') | |
@UseGuards(SSOAuthGuard) | |
login() { | |
return | |
} | |
@Get('callback') | |
@UseGuards(SSOAuthGuard) | |
callback(@User() user: any, @Passport() passport: any) { | |
return passport.logIn(user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment