gladly-team / next-firebase-auth

Simple Firebase authentication for all Next.js rendering strategies
https://nfa-example-git-v1x-gladly-team.vercel.app/
MIT License
1.33k stars 290 forks source link

How to resolve the return type of getServerSideProps? #695

Closed MathiasPawshake closed 6 months ago

MathiasPawshake commented 7 months ago

Hi

I looked into the example page: https://github.com/gladly-team/next-firebase-auth/blob/main/example/pages/ssr-no-token.tsx There you will see that the export default is the following:

export default withUser<DataType>({
  whenUnauthedAfterInit: AuthAction.REDIRECT_TO_LOGIN,
})(Demo)

The props of the page will be DataType which is fine. The only issue is that when you would forget to pass favoriteColor in the getServerSideProps, typescript will not throw an error that this property is missing.

If we would declare the getServerSideProps as following (without the next-firebase-auth, just as an example):

export const getServerSideProps: GetServerSideProps<DataType> = (ctx) => {
    // other code
    return {
        props: {
            favoriteColor: data.favoriteColor,
        },
    };
};

We would get a typescript error that favoriteColor is missing.

Is there a way to achieve this with the current typescript setup in next-firebase-auth?