Next.js Discord

Discord Forum

Why is my session of NextAuth always null

Unanswered
Blue swimming crab posted this in #help-forum
Open in Discord
Blue swimming crabOP
export const getStaticProps: GetStaticProps<DashboardProps> = async () => {
    try {
        // Get the session
        const session = await getSession();
        console.log('Session:', session);

        if (!session) {
            return {
                redirect: {
                    destination: '/auth/signin',
                    permanent: false,
                },
            };
        }

        const userResponse = await axios.get(`/api/user/${session.user?.name}`, {
            maxRedirects: 5,
        });

        return {
            props: {
                session,
                user: userResponse.data,
            },
        };
    } catch (error) {
        console.error('Error fetching data:', error);

        // If an error occurs, consider it as a not found scenario
        return {
            notFound: true,
        };
    }
};


my session is always null but i did log in.....

1 Reply

Blue swimming crabOP
i use discord oauth with nextjs