Next.js Discord

Discord Forum

Hiding result in http://localhost:3000/api/auth/session

Unanswered
Boreal Chickadee posted this in #help-forum
Open in Discord
Boreal ChickadeeOP
I'm using next auth in my app and I'm putting the user id in the session because in my context provider I have to check for subscription in the db (with supabase client) and I need the user id for it. I don't like it being seen in the network under session, is it good for security? otherwise, I'm not sure how to get it completely in the server side and only when needed, while my context is client side.
Here is a snippet of my code with how I currently do it, putting the id on the session:

export const MyUserContextProvider = (props: Props) => {
    const { data: session } = useSession();

    const user = session?.user;

    const [isLoadingData, setIsloadingData] = useState(false);
    const [userDetails, setUserDetails] = useState<UserDetails | null>(null);
    const [subscription, setSubscription] = useState<Subscription | null>(null);


    const getUserDetails = () => supabaseClient.from('users').select('*').eq('id', user?.id).single();

    const getSubscription = () =>
    supabaseClient
            .from('subscriptions')
            .select('*, prices(*, products(*))')
            .eq('user_id', user.id)
            .in('status', ['trialing', 'active'])
            .single();

// ... rest of the context

2 Replies

Why don't you want to expose the user ID to the client?
Boreal ChickadeeOP
no particular reason, was just wondering if it's safe