Skip to content
Discussion options

You must be logged in to vote

I simplified the auth component and stuck to the example. I had also a couple of unrelated issues, though, possibly causing the build errors. Now, this work like a charm !

Final auth.tsx

import {useEffect} from "react";
import {signIn, useSession} from "next-auth/react";

const Auth = ({ children }) => {
    const { data: session, status } = useSession({required: true})
    const isUser = !!session?.user

    useEffect(() => {
        if (status !== "loading" && !isUser) {
            signIn();
        }
    }, [status, isUser]);


    if (isUser) {
        return children
    }

    return <div>Loading...</div>;
};

export default Auth;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by KojoEnch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
question Ask how to do something or how something works
1 participant
Converted from issue

This discussion was converted from issue #3772 on February 01, 2022 06:50.