firebase / firebase/firebase-tools
Can't access `currentUser` and `firebaseApp` from `res.locals` on `getServerSideProps`
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.3k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 84
Description
### [REQUIRED] Environment info
**firebase-tools:** 11.23.1
**Platform:** macOS
### [REQUIRED] Test case
Create a project using NextJs and Firebase Auth. Create a page that accesses the auth state from a `getServerSideProps` doing `res.locals.currentUser`.
NextJs Code:
```ts
interface Props {
serverTime: number;
locals: string;
}
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
const locals = JSON.stringify((res as any).locals);
return { props: { serverTime: Date.now(), locals } };
};
export default function Home({ serverTime, locals }:Props) {
const auth = useAuth();
return (
Firebase Next SSR Auth
Server time: { serverTime }
locals: {locals}
{ auth === undefined/*loading*/ ?
Loading...
:auth.user === null/*not logged in*/ ? Login :
Auth state: {JSON.stringify(auth, null, 2)}
Logout
}
)
}
```
This is what the pages return. Notice that `locals` don't have the `currentUser` value.

Example repo: https://github.com/ErickJoestar/Firebase-Next-SSR-Auth/tree/auth-ssr
### [REQUIRED] Steps to reproduce
1. Initialize a project with NextJs
2. Enable web frameworks `firebase experiments:enable webframeworks`
3. Init hosting firebase `init hosting`
5. Create a page that uses getServerSideProps
6. Implement Firebase Auth
7. Access the Auth state from `getServerSideProps`
8. Deploy the app
### [REQUIRED] Expected behavior
The current user should be accessible from `res.locals.currentUser` on `getServerSideProps`
### [REQUIRED] Actual behavior
There is no `currentUser`
Contributor guide
Assessment
This issue has not been assessed yet.