Skip to content

Commit 9280b01

Browse files
committed
fix: Check if client in auth-callback
1 parent 0cb4195 commit 9280b01

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/app/pages/(auth)/auth-callback.page.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
22
import { Router } from '@angular/router';
3+
import { CommonModule, isPlatformBrowser } from '@angular/common';
34
import { SupabaseService } from '~/app/services/supabase.service';
45
import { GlobalMessageService } from '~/app/services/messaging.service';
56
import { ErrorHandlerService } from '~/app/services/error-handler.service';
@@ -17,6 +18,7 @@ export default class AuthCallbackComponent implements OnInit {
1718
private messagingService: GlobalMessageService,
1819
private errorHandlerService: ErrorHandlerService,
1920
private hitCountingService: HitCountingService,
21+
@Inject(PLATFORM_ID) private platformId: Object,
2022
) {}
2123

2224
private errorHappened(error: Error | any) {
@@ -29,14 +31,24 @@ export default class AuthCallbackComponent implements OnInit {
2931
}
3032

3133
async ngOnInit(): Promise<void> {
34+
if (!isPlatformBrowser(this.platformId)) {
35+
return;
36+
}
37+
38+
try {
3239
const { data, error } = await this.supabaseService.supabase.auth.exchangeCodeForSession(window.location.href);
33-
if (error) {
40+
if (error) {
41+
this.errorHappened(error);
42+
return;
43+
}
44+
} catch (error) {
3445
this.errorHappened(error);
46+
return;
3547
}
48+
3649
// Successfully logged in
3750
this.hitCountingService.trackEvent('auth_login_done', { method: 'social' });
3851
this.messagingService.showSuccess('Authenticated', 'Successfully logged in');
3952
this.router.navigate(['/']);
40-
4153
}
4254
}

0 commit comments

Comments
 (0)