firebase / firebase/firebase-js-sdk
Inaccurate return type on signInWithEmailAndPassword
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 37
Description
### Operating System
Linux 6.15.2
### Environment (if applicable)
Chromium 137.0.7151.104
### Firebase SDK Version
11.9.1
### Firebase SDK Product(s)
Functions
### Project Tooling
Vite 7.0.0 with TS 5.8.3
### Detailed Problem Description
We're logging a user in with `signInWithEmailAndPassword` and using the `email`, `accessToken`, and `refreshToken` returned on the `user` object. This is working as expected. The issue is that property `accessToken` does not exist on type `User`:

Here are the settings we are instantiating the app with:
```
const firebaseConfig: FirebaseOptions = {
apiKey: "...",
authDomain: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
```
Adding a log in to check the response returned by `signInWithEmailAndPassword` shows this:


So, there is definitely an accessToken returned when the type says there is not, so we have a type conflict between what is documented and what is actually happening.
As a workaround, I am typecasting the following:
```
// TODO improve type safety by getting Firebase to update their types as accessToken is not present on the types
// but is present in the response.
const {user} = await signInWithEmailAndPassword(auth, email, password) as unknown as {user: User & OAuthCredential}
```
This works, but if the SDK gets an update that changes anything on that function my app could break.
### Steps and code to reproduce issue
Set up a firebas project with the latest SDK (v11.9.1 as of now)
Use the following TS code:
```
import {FirebaseOptions, initializeApp} from "firebase/app";
import {getAuth, signInWithEmailAndPassword} from "firebase/auth";
const firebaseConfig: FirebaseOptions = {
apiKey: "...",
authDomain: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
async function test() {
const {user} = await signInWithEmailAndPassword(auth, email, password);
user.accessToken; // should see type error here
}
test().then()
```
To check the functionality of the code above, just insert a valid auth object, email and password.
Contributor guide
Assessment
This issue has not been assessed yet.