selectLoginEmail$(): Observable<string>¶
The selectLoginEmail$ method allows to get an email that a given user currently logs in with. The user must be authorized in order to perform this action.
Returned value¶
A returned value has a type of Observable<string> that represents an email of a currently authorized user.
Example¶
In this example we make a AuthenticationApi call to get an email of a currently authorized user with the selectLoginEmail$ method and if it's different than the email we want to set, we call a setLoginEmail to change it.
useStorefront(async (storefront) => {
const authenticationApi = await storefront.getApi('AuthenticationApi');
const emailToSet = 'differentemail@example.com';
const currentEmail$ = authenticationApi.selectLoginEmail$();
currentEmail$.subscribe((currentEmail) => {
if (currentEmail !== emailToSet) {
authenticationApi.setLoginEmail(emailToSet);
}
});
});