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,11 +105,9 @@ class AuthProvider extends React.Component<
|
|||
if (!!token && !user) {
|
||||
this.verifyToken(token);
|
||||
} else {
|
||||
if (isCredentialsManagementAPISupported) {
|
||||
loginWithCredentialsManagementAPI(this.login);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
login = async (email: string, password: string) => {
|
||||
const { tokenAuth } = this.props;
|
||||
|
@ -117,10 +115,8 @@ 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -4,14 +4,17 @@ export const isSupported =
|
|||
navigator.credentials && navigator.credentials.preventSilentAccess;
|
||||
|
||||
export function login(loginFn: (id: string, password: string) => void) {
|
||||
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) {
|
||||
if (isSupported) {
|
||||
const cred = new PasswordCredential({
|
||||
iconURL: user.avatar ? user.avatar.url : undefined,
|
||||
id: user.email,
|
||||
|
@ -19,4 +22,5 @@ export function saveCredentials(user: User, password: string) {
|
|||
password
|
||||
});
|
||||
navigator.credentials.store(cred);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue