Skip to content

Commit

Permalink
fix: vk oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Averito committed Jan 27, 2024
1 parent 56427a1 commit b470216
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/src/decorators/auth.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { UseGuards } from '@nestjs/common'
import { Reflector } from '@nestjs/core'
import { AuthGuard } from '@guards/auth.guard'

export const Auth = () => {
return UseGuards(new AuthGuard())
return UseGuards(new AuthGuard(new Reflector()))
}
7 changes: 7 additions & 0 deletions server/src/guards/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'
import { Reflector } from '@nestjs/core'
import { PUBLIC_KEY } from '@decorators/public.decorator'

@Injectable()
export class AuthGuard implements CanActivate {
constructor(private readonly reflector: Reflector) {}

async canActivate(context: ExecutionContext): Promise<any> {
const allow = this.reflector.get<boolean>(PUBLIC_KEY, context.getHandler())
if (allow) return true

const request = context.switchToHttp().getRequest()
return request.isAuthenticated()
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/strategies/vk.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class VkStrategy extends PassportStrategy(Strategy, 'vk') {
{
clientID: configService.get('VK_CLIENT_ID'),
clientSecret: configService.get('VK_CLIENT_SECRET'),
callbackURL: configService.get('Vk_REDIRECT_URI'),
callbackURL: configService.get('VK_REDIRECT_URI'),
profileFields: ['id', 'displayName', 'photos', 'emails'],
scope: ['email'],
lang: 'ru'
Expand Down

0 comments on commit b470216

Please sign in to comment.