I'm very confused about how to get the current user with SSR to get some user data.
I've been using the context API with react, and it's been working so far, until I need SSR to get data from an API. I want to get the current user id, so I can get a token that is stored in Firestore.
Auth.js
export const AuthContext = createContext();
export function AuthProvider({ children }) {
const [currentUser, setCurrentUser] = useState(null);
useEffect(() => {
onAuthStateChanged(auth, (user) => {
setCurrentUser(user);
});
}, []);
return (
<AuthContext.Provider value={{ currentUser }}>
{children}
</AuthContext.Provider>
);
}
SSR
export async function getStaticProps() {
const api = {
auth: "token",
};
//fetch api
return {
props: {
data,
},
};
}