-
-
Save musaghauri/de90be3f52f3d51804c311df78a23345 to your computer and use it in GitHub Desktop.
React Auth App - login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Frontend call for login | |
onLoginUser = async (data) => { | |
this.setState({ error: false, loading: true }); | |
const requestBody = { data }; | |
const requestURL = '/api/signin'; | |
const options = createRequestOptions('POST', requestBody); | |
const response = await request(requestURL, options); | |
if(!response.err) { | |
this.setState({ loading: false }); | |
const user = response.data; | |
cookies.save("token", user.token); | |
Router.push('/profile'); | |
} else { | |
this.setState({ error: response.err.reason, loading: false }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment