I have a react app ( typescript ) and want to integrate google authentication.
The authentication test works, but needs to extend the functionality
It just logs info to console
const responseMessage = (response: any) => {
console.log(response);
};
const errorMessage = (error) => { //this is commented in typescript
console.log(error);
};
Because the example is javascript, it does not fit in typescript model
https://blog.logrocket.com/guide-adding-google-login-react-app/
I had to sacrifice onError={errorMessage} from the below, as the function expects type to be specified for "error" and not accepting ? ( not specifying type or specifying :any both are error )
< GoogleLogin onSuccess={responseMessage} />
Question:
How can I write real onSuccess to navigate to a proper page (or same page with signin changing to logout ) and also fix my onError
Edit:
Initially I have login button, and after login I am still having that button. I am new to react and typescript, so struggling to beautify my page to give the feel to the user that the login task is complete, and remove/hide that button (Sign in as… after success login). I thought it will be out of the box, but looks like I have use localStorage and toggle
2
Answers
This is how I updated my code
Only sad part is google login button alignment, which is a different problem
The type declaration of
GoogleLogin
are as following:This means that
onError
method does not take any parameter. Try writing errorMessage as follows:You can write responseMessage as follows: