Skip to content
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

Retry transitions after page reloads #2808

Open
Windvis opened this issue Jul 30, 2024 · 0 comments
Open

Retry transitions after page reloads #2808

Windvis opened this issue Jul 30, 2024 · 0 comments

Comments

@Windvis
Copy link

Windvis commented Jul 30, 2024

ember-simple-auth supports retrying transitions after the session is authenticated, but this only works if the page isn't refreshed. session.attemptedTransition isn't persisted, so the info is gone after a reload.

ember-simple-auth does already support a cookie-based retry, but that is only enabled during FastBoot. Would it be an option to either always use this cookie-based setup, or make it an opt-in somehow?

Our use-case
We have an authenticator that redirects users to an authentication server on a different domain (which then redirects back to the app with a token), but as a result the original transition information is lost.

We can hook into the cookie-based redirect setup by writing the url to the ember_simple_auth-redirectTarget cookie ourselves (in the overriden requireAuthentication method of our app's SessionService). But it would be nice if this wouldn't require custom app code.

Code of our workaround
export default class SessionService extends BaseSessionService {
  @service router;

  requireAuthentication(transition, routeOrCallback) {
    const isAuthenticated = super.requireAuthentication(
      transition,
      routeOrCallback
    );

    if (!isAuthenticated) {
      const COOKIE_NAME = 'ember_simple_auth-redirectTarget';
      const redirectUrl = routeInfoUrl(transition.to, this.router); // This is a util that reimplements `transition.intent.url` with public APIs
      document.cookie = `${COOKIE_NAME}=${redirectUrl};path=/;samesite=strict`;
    }

    return isAuthenticated;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant