Skip to content

Instantly share code, notes, and snippets.

@DScheglov
Last active November 16, 2020 11:20
Show Gist options
  • Save DScheglov/26c06f5e3800555a617b3f0c9fb8e2b7 to your computer and use it in GitHub Desktop.
Save DScheglov/26c06f5e3800555a617b3f0c9fb8e2b7 to your computer and use it in GitHub Desktop.
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 };
})
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