1- import { Component , OnInit } from '@angular/core' ;
1+ import { Component , OnInit , OnDestroy } from '@angular/core' ;
22import { CommonModule } from '@angular/common' ;
33import { FormControl , FormGroup , Validators , ReactiveFormsModule } from '@angular/forms' ;
44import { MatButtonModule } from '@angular/material/button' ;
@@ -7,6 +7,8 @@ import { MatFormFieldModule } from '@angular/material/form-field';
77import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' ;
88import { ClerkService } from '@minsky/core' ;
99import { ElectronService } from '@minsky/core' ;
10+ import { ActivatedRoute } from '@angular/router' ;
11+ import { Subject , take } from 'rxjs' ;
1012
1113@Component ( {
1214 selector : 'minsky-login' ,
@@ -22,7 +24,7 @@ import { ElectronService } from '@minsky/core';
2224 MatProgressSpinnerModule ,
2325 ] ,
2426} )
25- export class LoginComponent implements OnInit {
27+ export class LoginComponent implements OnInit , OnDestroy {
2628 loginForm = new FormGroup ( {
2729 email : new FormControl ( '' , [ Validators . required , Validators . email ] ) ,
2830 password : new FormControl ( '' , [ Validators . required ] ) ,
@@ -32,17 +34,40 @@ export class LoginComponent implements OnInit {
3234 errorMessage = '' ;
3335 isAuthenticated = false ;
3436
35- constructor ( private clerkService : ClerkService , private electronService : ElectronService ) { }
37+ private destroy$ = new Subject < void > ( ) ;
38+
39+ constructor (
40+ private clerkService : ClerkService ,
41+ private electronService : ElectronService ,
42+ private route : ActivatedRoute
43+ ) { }
3644
3745 async ngOnInit ( ) {
46+ this . route . queryParams . pipe ( take ( 1 ) ) . subscribe ( ( params ) => {
47+ this . initializeSession ( params [ 'authToken' ] ) ;
48+ } ) ;
49+ }
50+
51+ private async initializeSession ( authToken : string | undefined ) {
3852 try {
3953 await this . clerkService . initialize ( ) ;
54+
55+ if ( authToken ) {
56+ await this . clerkService . setSession ( authToken ) ;
57+ }
58+
4059 this . isAuthenticated = await this . clerkService . isSignedIn ( ) ;
4160 } catch ( err ) {
42- this . errorMessage = 'Failed to initialize authentication.' ;
61+ this . errorMessage = 'Session expired. Please sign in again.' ;
62+ this . isAuthenticated = false ;
4363 }
4464 }
4565
66+ ngOnDestroy ( ) {
67+ this . destroy$ . next ( ) ;
68+ this . destroy$ . complete ( ) ;
69+ }
70+
4671 get email ( ) {
4772 return this . loginForm . get ( 'email' ) ;
4873 }
0 commit comments