I want users to be able to choose a role as part of the login process.
After user gives his username and password, server sends back the roles he have.
How can I achieve a dialog, where user can choose a role from the list of owned roles, before the login function of authProvider ends?
The login function is a regular JavaScript function, not a React function component, so I can not call hooks from it (like useContext).
I have two guess:
In the
LoginFormpass anasynccallback function to theloginmethod (what is created byuseLogin(). After server responds in theloginfunction with therolesof theuser, call this callback function withawait. In this callback function, I can make the 'Choose a Role' Modal visible. I just don't see, how can I achieve that the program waits until the user hits thesubmitbutton in the 'Choose a Role' Modal, and only than return a resolved Promise. Is it possible in JS?Create a 'pre-login' form, which accept the
usernameandpassword, sends it to the backend, which returns the roles, show the 'Choose a Role' Modal, and call theauthProviderloginfunction only when user submits a role.
I'm really curious about your opinion and thoughts on it.
                        
The
loginfunction returned by theuseLoginhook accepts a second argument in addition to the credentials:redirectTo. You can provide a custom route which would display either a dedicated page for choosing the role or the login page with a sub route displaying your modal if you really want a modal.Once the user has chosen its role, you may then redirect to the admin home page by using the
useRedirecthook.