-
Notifications
You must be signed in to change notification settings - Fork 314
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
fix(authenticator): fetch current user on routed apps after refresh #1580
Changes from 9 commits
df53b24
7e00926
dbe5256
0688fc4
0b2a066
fc71b28
4f086c9
e777730
37588e0
487a9a3
924e906
c3a7daf
a72d2c3
7857497
43119e4
b8c36bb
8ce83b1
111bf94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@aws-amplify/ui-react": patch | ||
"@aws-amplify/ui": patch | ||
"@aws-amplify/ui-vue": patch | ||
"@aws-amplify/ui-angular": patch | ||
--- | ||
|
||
fix(authenticator): look for current user on routed apps whenever app refreshes |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,47 +25,58 @@ export function createAuthenticatorMachine() { | |
context: { | ||
user: undefined, | ||
config: {}, | ||
services: {}, | ||
services: { ...defaultServices }, | ||
wlee221 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
actorRef: undefined, | ||
}, | ||
states: { | ||
// See: https://xstate.js.org/docs/guides/communication.html#invoking-promises | ||
idle: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Knowing that, |
||
on: { | ||
INIT: { | ||
invoke: { | ||
src: 'getCurrentUser', | ||
onDone: { | ||
actions: 'setUser', | ||
target: 'authenticated', | ||
}, | ||
onError: { | ||
target: 'setup', | ||
actions: 'configure', | ||
}, | ||
}, | ||
}, | ||
setup: { | ||
invoke: [ | ||
{ | ||
// TODO Wait for Auth to be configured | ||
src: 'getCurrentUser', | ||
onDone: { | ||
actions: 'setUser', | ||
target: 'authenticated', | ||
initial: 'waitConfig', | ||
states: { | ||
waitConfig: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this stage, we confirmed that no user has signed in yet. Now we wait for |
||
on: { | ||
INIT: { | ||
actions: 'configure', | ||
target: 'applyConfig', | ||
}, | ||
}, | ||
onError: [ | ||
}, | ||
applyConfig: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we have all the machine props ready, we apply those configs to get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
invoke: { | ||
// TODO Wait for Auth to be configured | ||
src: 'getAmplifyConfig', | ||
onDone: { | ||
actions: 'applyAmplifyConfig', | ||
target: 'goToInitialState', | ||
}, | ||
}, | ||
}, | ||
goToInitialState: { | ||
always: [ | ||
{ | ||
target: 'signUp', | ||
target: '#authenticator.signUp', | ||
cond: 'isInitialStateSignUp', | ||
}, | ||
{ | ||
target: 'resetPassword', | ||
target: '#authenticator.resetPassword', | ||
cond: 'isInitialStateResetPassword', | ||
}, | ||
{ target: 'signIn' }, | ||
{ target: '#authenticator.signIn' }, | ||
], | ||
}, | ||
{ | ||
src: 'getAmplifyConfig', | ||
onDone: { | ||
actions: 'applyAmplifyConfig', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
signIn: { | ||
initial: 'spawnActor', | ||
|
@@ -220,7 +231,6 @@ export function createAuthenticatorMachine() { | |
} | ||
|
||
// Prefer explicitly configured settings over default CLI values\ | ||
|
||
const { | ||
loginMechanisms, | ||
signUpAttributes, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously
authMachine
got stuck inidle
state until anAuthenticator
in DOM sends anINIT
event on mount. NowauthMachine
starts independently (see state machine changes below), and will explicitly ask for config fromAuthenticator
once it's insetup
state.Once
Authenticator
sees that state is insetup
, it'll send the usualINIT
event.