Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 2e43e68

Browse files
authored
Feature/authentication callback (#28)
* update environment client id * remove useless commented code * allow custom callback on process * lintfixing
1 parent d7882b8 commit 2e43e68

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

projects/cryptr/cryptr-angular/src/lib/auth.service.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -226,40 +226,39 @@ export class AuthService implements OnDestroy {
226226
}).finally(() => {
227227
this.isLoading$.next(false);
228228
});
229-
// this.cryptrClient.handleRefreshTokens().then((res) => {
230-
// console.log(`handlerefreshTokens ${res === true}`);
231-
// console.log(res);
232-
// this.updateCurrentAuthState(res === true);
233-
// }).catch((error) => {
234-
// this.updateCurrentAuthState(false);
235-
// }).finally(() => {
236-
// this.isLoading$.next(false);
237-
// });
238229
}
239230
}
240231

241-
fullAuthenticateProcess(stateUrl?: string): Observable<boolean | UrlTree> {
232+
private defaultAuthenticationCallback(isAuthenticated: boolean, stateUrl?: string): boolean {
242233
const { audience, default_locale } = this.config();
243234
const redirectUri = audience.concat(stateUrl || '');
244-
// const tree = this.router.parseUrl(stateUrl)
245-
// const newTree = this.cleanUrlTree(tree, stateUrl)
235+
if (isAuthenticated) {
236+
return true;
237+
} else {
238+
if (this.configFactory.get().has_ssr) {
239+
this.signInWithRedirect(DEFAULT_SCOPE, default_locale, redirectUri);
240+
} else {
241+
this.signInWithRedirect();
242+
}
243+
return false;
244+
}
245+
}
246+
247+
fullAuthenticateProcess(
248+
stateUrl?: string,
249+
callback?: (isAuthenticated: boolean, stateUrl?: string) => boolean
250+
): Observable<boolean | UrlTree> {
246251
return combineLatest(
247252
[this.isLoading$, this.authenticated$]
248253
).pipe(
249254
filter(([isLoading, isAuthenticated]) => {
250255
return !isLoading;
251256
}),
252257
map(([isLoading, isAuthenticated]) => {
253-
if (isAuthenticated) {
254-
this.cleanRouteState();
255-
return true;
258+
if (callback) {
259+
return callback(isAuthenticated, stateUrl);
256260
} else {
257-
if (this.configFactory.get().has_ssr) {
258-
this.signInWithRedirect(DEFAULT_SCOPE, default_locale, redirectUri);
259-
} else {
260-
this.signInWithRedirect();
261-
}
262-
return false;
261+
return this.defaultAuthenticationCallback(isAuthenticated, stateUrl);
263262
}
264263
})
265264
);

projects/playground/src/environments/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const environment = {
88
cryptrConfig: {
99
audience: 'http://localhost:4200',
1010
tenant_domain: 'shark-academy',
11-
client_id: '79742198-b3d6-4565-bca2-276f63162129',
11+
client_id: 'fea92afe-3bf5-4f55-b772-1d0fa14d325f',
1212
default_redirect_uri: 'http://localhost:4200/',
1313
// region: 'us',
1414
cryptr_base_url: 'http://localhost:4000',

0 commit comments

Comments
 (0)