Wrap code into if supported check
This commit is contained in:
parent
6d6312248d
commit
4e2ae6ad2b
2 changed files with 18 additions and 18 deletions
|
@ -105,9 +105,7 @@ class AuthProvider extends React.Component<
|
|||
if (!!token && !user) {
|
||||
this.verifyToken(token);
|
||||
} else {
|
||||
if (isCredentialsManagementAPISupported) {
|
||||
loginWithCredentialsManagementAPI(this.login);
|
||||
}
|
||||
loginWithCredentialsManagementAPI(this.login);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,9 +115,7 @@ class AuthProvider extends React.Component<
|
|||
|
||||
tokenAuthFn({ variables: { email, password } }).then(result => {
|
||||
if (result && !result.data.tokenCreate.errors.length) {
|
||||
if (isCredentialsManagementAPISupported) {
|
||||
saveCredentials(result.data.tokenCreate.user, password);
|
||||
}
|
||||
saveCredentials(result.data.tokenCreate.user, password);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -4,19 +4,23 @@ export const isSupported =
|
|||
navigator.credentials && navigator.credentials.preventSilentAccess;
|
||||
|
||||
export function login(loginFn: (id: string, password: string) => void) {
|
||||
navigator.credentials.get({ password: true }).then(credential => {
|
||||
if (credential instanceof PasswordCredential) {
|
||||
loginFn(credential.id, credential.password);
|
||||
}
|
||||
});
|
||||
if (isSupported) {
|
||||
navigator.credentials.get({ password: true }).then(credential => {
|
||||
if (credential instanceof PasswordCredential) {
|
||||
loginFn(credential.id, credential.password);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function saveCredentials(user: User, password: string) {
|
||||
const cred = new PasswordCredential({
|
||||
iconURL: user.avatar ? user.avatar.url : undefined,
|
||||
id: user.email,
|
||||
name: user.firstName ? `${user.firstName} ${user.lastName}` : undefined,
|
||||
password
|
||||
});
|
||||
navigator.credentials.store(cred);
|
||||
if (isSupported) {
|
||||
const cred = new PasswordCredential({
|
||||
iconURL: user.avatar ? user.avatar.url : undefined,
|
||||
id: user.email,
|
||||
name: user.firstName ? `${user.firstName} ${user.lastName}` : undefined,
|
||||
password
|
||||
});
|
||||
navigator.credentials.store(cred);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue