1- import { Component , OnInit } from '@angular/core' ;
1+ import { Component , Inject , OnInit , PLATFORM_ID } from '@angular/core' ;
22import { Router } from '@angular/router' ;
3+ import { CommonModule , isPlatformBrowser } from '@angular/common' ;
34import { SupabaseService } from '~/app/services/supabase.service' ;
45import { GlobalMessageService } from '~/app/services/messaging.service' ;
56import { 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