I use passport-faceebook in nestjs application and have a controller in it with /callback route.
After I doing some authenticating stuff I call redirect to client home page. Google-strategy do everything in the same tab (safari and chrome). But Facebook-strategy leave two tabs after authenticating. I expect only home page tab and not need auth page to be left.
In chrome facebook-strategy redirects in one tab as expected.
This behavior only in safari.
All browsers were updated up to last versions.
@Controller('auth')
export class AuthController {
constructor(
private authService: AuthService,
private cookiesService: CookiesService,
) { }
@Get('facebook')
@UseGuards(FacebookAuthGuard)
fbAuth() {}
@Get('facebook/callback')
@UseGuards(FacebookAuthGuard)
async fbAuthCallback(
@Req() req: Request,
@Res() res: Response,
@Query('state') state: string,
) {
const {
accessToken,
refreshToken,
} = await this.authService.authWithProvider(req.user as CreateUserDto);
this.cookiesService.setAccessTokenCookie(res, accessToken);
this.cookiesService.setRefreshTokenCookie(res, refreshToken);
const { origin } = JSON.parse(state);
res.redirect(`${process.env.CLIENT_URL}${origin || ''}`);
}
@UseGuards(GoogleAuthGuard)
@Get('google')
googleAuth() { }
@UseGuards(GoogleAuthGuard)
@Get('google/callback')
async googleAuthCallback(
@Req() req: Request,
@Res() res: Response,
@Query('state') state: string,
) {
const {
accessToken,
refreshToken,
} = await this.authService.authWithProvider(req.user as CreateUserDto);
this.cookiesService.setAccessTokenCookie(res, accessToken);
this.cookiesService.setRefreshTokenCookie(res, refreshToken);
const { origin } = JSON.parse(state);
res.redirect(`${process.env.CLIENT_URL}${origin || ''}`);
}
}
Expect to have one tab after auth in safari with facebook-pasport
tried to change client side request (using nextjs router from “next/navigation”)
router.push(`${process.env.API_URL}/auth/facebook?origin=${encodeURIComponent(path || '')}`);
window.open(`${process.env.API_URL}/auth/facebook?origin=${encodeURIComponent(path || '')}`, '_self');