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

Hub(auth) is not firing, when logged on via refresh/existing cookie log on (working in v5 not working in v6) #12739

Closed
4 tasks done
myonara opened this issue Dec 20, 2023 · 6 comments
Assignees
Labels
Auth Related to Auth components/category Hub Related to Hub category transferred This issue was transferred from another Amplify project

Comments

@myonara
Copy link

myonara commented Dec 20, 2023

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

Angular

Which UI component?

Authenticator

How is your app built?

angular/amplify

What browsers are you seeing the problem on?

Chrome, Firefox

Which region are you seeing the problem in?

eu-central-1 / localhost execution

Please describe your bug.

In version 6 I'm getting events ob the hub-Channel "auth" for signedin and signedup, but getting no hub event, when I refresh the browser and have a valid auth cookie. In version 5 I'm getting signin events also, when I'm refreshing the browser with an auth cookie. Side question: Also I used Auth.currentSession in V5, which is missing in V6, is there a replacement for this?

What's the expected behaviour?

The hub-channel auth can get also re signed in events.

Help us reproduce the bug!

Just do a default project with auth in V6 and listen to the Hub-Auth-Channel during the steps of singing up/signing in and refresh browser after logged in.

Code Snippet

// Put your code below this line.
    this.hubListenerCancelToken = Hub.listen('auth', async (msg: any) => {
      console.log('hub-1', msg.payload.event);
    }

Console log output

// getting signin,signup in V5 also for refreshing page with an auth cookie set.
// getting signedin,sgnedup in V6 but not signedin during reloading the page with an auth cookie!

Additional information and screenshots

No response

@github-actions github-actions bot added the pending-triage Issue is pending triage label Dec 20, 2023
@myonara myonara changed the title Hub(auth) is not firing, when logged on via refesh/eisting cookie log on (working in v5 not working in v6) Hub(auth) is not firing, when logged on via refresh/existing cookie log on (working in v5 not working in v6) Dec 20, 2023
@calebpollman calebpollman transferred this issue from aws-amplify/amplify-ui Dec 21, 2023
@cwomack cwomack self-assigned this Dec 21, 2023
@cwomack cwomack added investigating This issue is being investigated Auth Related to Auth components/category Hub Related to Hub category and removed pending-triage Issue is pending triage labels Dec 26, 2023
@cwomack
Copy link
Member

cwomack commented Jan 25, 2024

Hello, @myonara and sorry for the delayed response on this issue. The equivalent to Auth.currentSession() from v5 would be the fetchAuthSession() potentially for what you're looking to use (docs here). There's also an updated section on the Auth events from Hub here if you'd like more details on how to use them in v6.

Let me know if that helps clear things up or if there's a specific use case or context we can help with further!

@cwomack cwomack added pending-response and removed investigating This issue is being investigated labels Jan 25, 2024
@nadetastic nadetastic added the transferred This issue was transferred from another Amplify project label Jan 30, 2024
@nadetastic
Copy link
Member

Hi @myonara following up here - let us know if the comment from @cwomack above addressed your issue. Thanks!

@myonara
Copy link
Author

myonara commented Feb 22, 2024

Sorry, just seen it now, thank you for the reminder. I will dig into the docs and code soon to clarify.

@myonara
Copy link
Author

myonara commented Feb 24, 2024

So I have tested the hints, @cwomack has given. Now my code is working again. Here are my observations:

  • There is no Hub Auth-Event "refreshToken" without using fetchAuthSession(). in v5 there was a signin, this is no longer in v6
  • Do not call fetchAuthSession({ forceRefresh: true }) within the the handling of "refreshToken", that produces an endless loop. The event is fired before the fetchAuthSession() is returning values in the client.
  • authToken and idToken is delivered with fetchAuthSession({ forceRefresh: true }), both have the identical sub field
  • the idToken is marked as optional in the definition, but it has useful fields like email,cognito:username, and cognito:groups (if the user is in any group)
  • didn't tested with social providers so far.
  • This was working with angular 17.0.7/17.2.2 and aws-amplify 6.0.8/6.0.17

@nadetastic
Copy link
Member

@myonara glad that the hints from @cwomack have you working again, let us know if you have any more questions on this.

@cwomack
Copy link
Member

cwomack commented Apr 4, 2024

@myonara, glad to hear you're unblocked! I'll close this issue then for now, but feel free to reply back if you still experience this or feel free to open a new issue if there's anything else that you run in to.

@cwomack cwomack closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auth Related to Auth components/category Hub Related to Hub category transferred This issue was transferred from another Amplify project
Projects
None yet
Development

No branches or pull requests

3 participants