'Property 'accessToken' does not exist on type 'User' && firebase is not defined
I am using TypeScript in my React application and I have an error "Property 'accessToken' does not exist on type 'User'" when getting an accessToken of user
My handler function in component:
const handleRegister = (email: string, password: string) => {
const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)
.then(({user}) => {
dispatch(setUser({
email: user.email,
token: user.accessToken,
id: user.uid
}));
});
}
after searching for a solution to this problem, I did this
token: (user as unknown as OAuthCredential).accessToken,
and IDE automatically added the following imports
import firebase from "firebase/compat";
import OAuthCredential = firebase.auth.OAuthCredential;
But after that I get an error in the console "Uncaught ReferenceError: firebase is not defined". I feel stupid but I don't understand how to solve it
Solution 1:[1]
do this see what results you get, i think you need result.user.accessToken but im not sure
signInWithEmailAndPassword(auth, email, password)
.then((result: any) => {
// Signed in
console.log(result)
// ...
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
