NextAuth Twitter authentication not working

Every time I attempt to authenticate with Twitter using the code I’ve implemented with NextAuth, I encounter issues. The authentication process involves storing the relevant data in a Supabase database. Despite my efforts to configure everything correctly, I’m running into obstacles that are preventing a successful authentication. Specifically, I suspect there might be issues related to how the authentication tokens or session information are being managed and stored in Supabase, but I’m not entirely sure where the problem lies. I’m seeking guidance on how to properly troubleshoot and resolve this issue so that Twitter authentication works seamlessly with my Next.js application:

import NextAuth from 'next-auth';
import TwitterProvider from 'next-auth/providers/twitter';
import { createClient } from '@supabase/supabase-js';

const supabase = createClient(
  process.env.NEXT_PUBLIC_SUPABASE_URL!,
  process.env.SUPABASE_SERVICE_ROLE_KEY!
);

export const authOptions = NextAuth({
  providers: [
    TwitterProvider({
      clientId: process.env.TWITTER_CLIENT_ID!,
      clientSecret: process.env.TWITTER_CLIENT_SECRET!,
    }),
  ],
  secret: process.env.NEXTAUTH_SECRET!,
  callbacks: {
   async jwt({ token, account, user }) {
   if (account) {
    token.accessToken = account.access_token;

    const { data, error } = await supabase
      .from('accountsx')
      .upsert({
        userid: user?.id,
        provider: account.provider,
        provideraccountid: account.providerAccountId,
        accesstoken: account.access_token,
        refreshtoken: account.refresh_token,
      }, {
        onConflict: 'provideraccountid',
      });

    if (error) {
      console.error('Error storing Twitter access token in Supabase:', error);
    }
  }
  return token;
},
async session({ session, token }) {
  session.accessToken = token.accessToken as string | undefined;
  return session;
    },
  },
});

export { authOptions as GET, authOptions as POST };

I get this error (I am sure from all the keys and callback url)

[next-auth][error][SIGNIN_OAUTH_ERROR] 
https://next-auth.js.org/errors#signin_oauth_error undefined {
  error: {
    statusCode: 401,
    data: '{"errors":[{"code":32,"message":"Could not authenticate you."}]}'
  },
  providerId: 'twitter',
  message: undefined
}

Problem

I tried and checked all the keys and parms, but I couldn’t sign in