Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleLogin = () => {
const name = this.state.username;
const password = this.state.password;
// this.gotoHomePage()
// this.props.store.dispatch(login(true));
const url =
env.API_HOST +
`:` +
env.API_PORT +
`/api/v1/login?grant_type=password&client_id=client@letsgo&client_secret=Va4a8bFFhTJZdybnzyhjHjj6P9UVh7UL&scope=read&username=${name}&password=${password}`;
// ! FOR DEVELOPMENT ONLY
// const url =
// env.API_HOST +
// `:` +
// env.API_PORT +
// `/api/v1/login?grant_type=password&client_id=client@letsgo&client_secret=Va4a8bFFhTJZdybnzyhjHjj6P9UVh7UL&scope=read&username=a@a.com&password=1234`;
axios
.get(url)
.then(res => {
if (res.hasOwnProperty('data') && res.data.hasOwnProperty('access_token')) {
const token = res.data.access_token;
axios
.get(env.API_HOST + `:` + env.API_PORT + `/api/v1/auth/me?access_token=${token}`)
.then(info => {
.then(res => {
if (res.hasOwnProperty('data') && res.data.hasOwnProperty('access_token')) {
const token = res.data.access_token;
axios
.get(env.API_HOST + `:` + env.API_PORT + `/api/v1/auth/me?access_token=${token}`)
.then(info => {
this.props.store.dispatch(set_user_info(info.data));
AsyncStorage.setItem('access_token', res.data.access_token);
ToastAndroid.show('Success', ToastAndroid.LONG);
this.gotoHomePage();
this.props.store.dispatch(login(true));
this.props.store.dispatch(set_access_token(res.data.access_token));
})
.catch(err => {
console.error(err);
});
}
})
.catch(err => {
async signup() {
const name = this.state.name;
const username = this.state.username;
const email = this.state.email;
const password = this.state.password;
const phone = this.state.phone;
const url = env.API_HOST + `:` + env.API_PORT + `/api/v1/register`;
axios
.post(url, { name, username, email, phone, password })
.then(res => {
if (res.hasOwnProperty('data') && res.data.hasOwnProperty('message') && res.data.message.toLowerCase() === 'registration successful') {
Actions.login();
}
})
.catch(e => {
console.error(e);
});
}
.then(res => {
axios
.get(
`${env.API_HOST}:${env.API_PORT}/api/v1/login?grant_type=client_credentials&client_id=google@letsgo&client_secret=Va4a8bFFhTJZdybnzyhjHjj6P9UVh7UL`
)
.then(res => {})
.catch(err => {
console.log(err);
});
})
.catch(err => {});
AsyncStorage.getItem('access_token').then(token => {
const userInfo = {
avatar: '',
email: this.state.email,
id: this.props.userInfo.id,
name: this.state.name,
phone: this.state.phone,
username: this.state.username
};
axios.post(env.API_HOST + `:` + env.API_PORT + `/api/v1/auth/me?access_token=${token}`, userInfo).then(res => {
if (res.hasOwnProperty('data') && res.data.message === 'Profile Updated') {
this.props.store.dispatch(set_user_info(userInfo));
}
});
});
}