-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move away from await in local-auth-guard
- Loading branch information
1 parent
56e8ac6
commit e4ec6f3
Showing
2 changed files
with
31 additions
and
32 deletions.
There are no files selected for viewing
19 changes: 7 additions & 12 deletions
19
services/workflows-service/src/auth/local/local-auth.guard.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,21 @@ | ||
import { Injectable, ExecutionContext } from '@nestjs/common'; | ||
import { CanActivate, Injectable, ExecutionContext } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { SupabaseService } from '../../supabase/supabase.service'; | ||
|
||
@Injectable() | ||
export class LocalAuthGuard extends AuthGuard('local') { | ||
export class LocalAuthGuard extends AuthGuard('local') implements CanActivate { | ||
constructor(private readonly supabaseService: SupabaseService) { | ||
super(); | ||
} | ||
|
||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const result = (await super.canActivate(context)) as boolean; | ||
canActivate(context: ExecutionContext): Promise<boolean> { | ||
const result = super.canActivate(context) as boolean; | ||
const request = context.switchToHttp().getRequest(); | ||
|
||
// Use the injected service | ||
if (result && request.user) { | ||
const fullUrl = request.protocol + '://' + request.get('host') + request.originalUrl; | ||
await this.supabaseService.logSignIn(fullUrl); | ||
this.supabaseService.logSignIn(fullUrl); | ||
} | ||
|
||
// Ensure the session is logged in (if using sessions) | ||
await super.logIn(request); | ||
|
||
return result; | ||
super.logIn(request); | ||
return Promise.resolve(result); | ||
} | ||
} |
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