-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
App state interface #240
Merged
Merged
App state interface #240
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add TokenId interface and User class export from auth0-spa-js
Update public-api.ts
Thanks for the PR. We believe having a typed Once auth0/auth0-spa-js#846 is merged and released, we should be able to update the Angular SDK by mostly adding some generic types to AuthService, something along the lines of: export interface NgAppState {
target?: string;
[key: string]: any;
}
export class AuthService<TAppState extends NgAppState = NgAppState> implements OnDestroy {
private appStateSubject$ = new ReplaySubject<TAppState>(1);
loginWithRedirect(options?: RedirectLoginOptions<TAppState>): Observable<void> {
return from(this.auth0Client.loginWithRedirect(options));
}
handleRedirectCallback(url?: string): Observable<RedirectLoginResult<TAppState>> {
return defer(() => this.auth0Client.handleRedirectCallback<TAppState>(url)).pipe(
withLatestFrom(this.authState.isLoading$),
tap(([result, isLoading]) => {
if (!isLoading) {
this.authState.refresh();
}
const appState = result?.appState;
const target = appState?.target ?? '/';
if (appState) {
this.appStateSubject$.next(appState);
}
this.navigator.navigateByUrl(target);
}),
map(([result]) => result)
);
}
} |
frederikprijck
approved these changes
Dec 1, 2021
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This little PR add two short interfaces to type the appState that can be passed to login command to be stored before redirect.
At the moment the only typed parameter is optional
target
but other ones could be added in the future, and custom ones are allowed by interface signature.This way, when writing a
loginWithRedirect(...)
call, bothappState
object both its stringtarget
property will be suggested by autocompletion.To get this working two interfaces have been created
and
With this setup, future angular specific options can be kept separated from
auth0-spa-js
code without interfering with it, since the assertions it issues on the extendedRedirectLoginOptions
only care about it being an object and about its basic properties types.