File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Injectable } from '@angular/core' ;
2+ import Descope from '@descope/web-js-sdk' ;
3+ import { environment } from '../environments/environment' ;
4+
5+ @Injectable ( {
6+ providedIn : 'root'
7+ } )
8+ export class OneTapService {
9+ private sdk : any ;
10+ private oneTapInitialized : boolean = false ;
11+
12+ constructor ( ) {
13+ const projectId = environment . descopeProjectId ;
14+ this . sdk = Descope ( { projectId : projectId , persistTokens : true , autoRefresh : true } ) ;
15+ }
16+
17+ // Method to display Google One Tap
18+ async displayOneTap ( ) : Promise < void > {
19+ if ( this . oneTapInitialized ) return ;
20+
21+ try {
22+ const resp = await this . sdk . fedcm . oneTap ( 'google' ) ;
23+ console . log ( "One Tap response:" , resp ) ;
24+ // Redirect on success
25+ window . location . replace ( "/dashboard" ) ;
26+ this . oneTapInitialized = true ;
27+ } catch ( error ) {
28+ console . error ( "Failed to display One Tap:" , error ) ;
29+ }
30+ }
31+
32+ // Method to check if the user is authenticated
33+ isAuthenticated ( ) : boolean {
34+ const sessionToken = this . sdk . getSessionToken ( ) ;
35+ if ( sessionToken ) {
36+ return ! this . sdk . isJwtExpired ( sessionToken ) ;
37+ }
38+ return false ;
39+ }
40+
41+ // Method to check if One Tap has been initialized
42+ isOneTapInitialized ( ) : boolean {
43+ return this . oneTapInitialized ;
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments