Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const currentUser = async () => {
try {
// check if user is authenticated
// try will throw if not
const user = await Auth.currentAuthenticatedUser();
// attributes are only updated here until re-auth
// so grab attributes from here
const attributes = await Auth.currentUserInfo();
const realuser = { ...user, ...{ attributes: attributes.attributes } };
setCurrentUser(realuser);
// attach sdk
// console.log("in load: realuser", realuser);
const sdkEnv = getSdkEnvironment(
SdkEnvironmentNames[`${config.SDK_ENV}`],
);
// check or set up local storage and initialize sdk connection
const sdk = new createSdk(
sdkEnv.setConfig('storageAdapter', localStorage),
);
await sdk.initialize();
// check if account is connected in local storage
.then(user => {
this.isLoading = false;
Auth.currentUserInfo()
.then(info => {
const payload = { username: user.username, jwt: user.signInUserSession.idToken.jwtToken };
this.$store.dispatch("setLoggedIn", payload );
this.statusMessage = "Loading user details";
console.log("current user info ", info);
console.log("initial JWT", user.signInUserSession.idToken.jwtToken)
if (!this.redirectTo) {
// No called route, send to root (/)
this.$router.push({
path: "/",
});
} else {
// When authenticated, forward to auth required route
this.$router.push({
path: this.redirectTo
getUser = async () => {
await Auth.currentUserInfo()
.then((data) => {
this.setState({ user: data.username });
})
.catch(error => console.log(`Error: ${error.message}`));
};
componentDidMount() {
Auth.currentUserInfo()
.then(user => this.setState({ user: user, path: user.id + '/' + today() + '/' }))
.catch(err => console.log(err));
}
localStorage.getItem(`@archanova:${network}:device:private_key`),
);
const deviceValue = JSON.parse(
localStorage.getItem(`@archanova:${network}:account_device`),
);
const store = await web3Service.getKeyStore(
'0x' + keyValue.data,
values.newPassword,
);
await Auth.updateUserAttributes(user, {
'custom:encrypted_ks': JSON.stringify(store),
'custom:device_address': deviceValue.device.address,
});
const attributes = await Auth.currentUserInfo();
console.log('attributes', attributes);
setCurrentUser( { ...currentUser, ...{ attributes: attributes.attributes } })
setSubmitting(false);
setAuthSuccess(true);
} catch (err) {
console.log('error changing pass: ', err);
setSubmitting(false);
setAuthError(err);
}
}}
>
getUser = async () => {
await Auth.currentUserInfo()
.then((data) => {
this.setState({ user: data.username });
console.log(`Current user: ${this.state.user}`);
})
.catch(error => console.log(`Error: ${error.message}`));
};
localStorage.getItem(`@archanova:${network}:device:private_key`),
);
const deviceValue = JSON.parse(
localStorage.getItem(`@archanova:${network}:account_device`),
);
const store = await web3Service.getKeyStore(
'0x' + keyValue.data,
values.oldPassword,
);
await Auth.updateUserAttributes(user, {
'custom:encrypted_ks': JSON.stringify(store),
'custom:device_address': deviceValue.device.address,
});
const attributes = await Auth.currentUserInfo();
console.log('attributes', attributes);
setCurrentUser( { ...currentUser, ...{ attributes: attributes.attributes } })
setSubmitting(false);
setAuthSuccess(true);
} catch (err) {
console.log('error changing pass: ', err);
setSubmitting(false);
setAuthError(err);
}
}}
>
componentDidMount() {
Auth.currentUserInfo()
.then(user => this.setState({ user: user, path: user.id + '/' + today() + '/' }))
.catch(err => console.log(err));
}
constructor(props) {
super(props);
this.state = {userInfo: null};
Auth.currentUserInfo().then(info => {
this.setState({userInfo: info});
})
}
Auth.currentSession().then(async (response) => {
const data = await Auth.currentAuthenticatedUser();
const userData = await Auth.currentUserInfo();
this.props.updateAuth({
isAuthenticating: false,
isAuthenticated: true,
userData,
identityId: data,
});
this.props.fetchAllOrders();
}).catch((error) => {
this.finishAuthentication();