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) {
|
if (!!token && !user) {
|
||||||
this.verifyToken(token);
|
this.verifyToken(token);
|
||||||
} else {
|
} else {
|
||||||
if (isCredentialsManagementAPISupported) {
|
loginWithCredentialsManagementAPI(this.login);
|
||||||
loginWithCredentialsManagementAPI(this.login);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,9 +115,7 @@ class AuthProvider extends React.Component<
|
||||||
|
|
||||||
tokenAuthFn({ variables: { email, password } }).then(result => {
|
tokenAuthFn({ variables: { email, password } }).then(result => {
|
||||||
if (result && !result.data.tokenCreate.errors.length) {
|
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;
|
navigator.credentials && navigator.credentials.preventSilentAccess;
|
||||||
|
|
||||||
export function login(loginFn: (id: string, password: string) => void) {
|
export function login(loginFn: (id: string, password: string) => void) {
|
||||||
navigator.credentials.get({ password: true }).then(credential => {
|
if (isSupported) {
|
||||||
if (credential instanceof PasswordCredential) {
|
navigator.credentials.get({ password: true }).then(credential => {
|
||||||
loginFn(credential.id, credential.password);
|
if (credential instanceof PasswordCredential) {
|
||||||
}
|
loginFn(credential.id, credential.password);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveCredentials(user: User, password: string) {
|
export function saveCredentials(user: User, password: string) {
|
||||||
const cred = new PasswordCredential({
|
if (isSupported) {
|
||||||
iconURL: user.avatar ? user.avatar.url : undefined,
|
const cred = new PasswordCredential({
|
||||||
id: user.email,
|
iconURL: user.avatar ? user.avatar.url : undefined,
|
||||||
name: user.firstName ? `${user.firstName} ${user.lastName}` : undefined,
|
id: user.email,
|
||||||
password
|
name: user.firstName ? `${user.firstName} ${user.lastName}` : undefined,
|
||||||
});
|
password
|
||||||
navigator.credentials.store(cred);
|
});
|
||||||
|
navigator.credentials.store(cred);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue