Back

createSession method doesn't return the `providerUID` in node-appwrite

  • 0
  • Self Hosted
  • Auth
Sam K
19 Mar, 2024, 13:03

Hi, I am trying to get the user uid from github on the server side in Nuxt. After login the session response it has the providerUid as empty string . I also tried with get the current session or current user is the same result.

I am using appwrite 1.5.3 selfhosted with nuxt and node-appwrites@latest

my code: login

TypeScript
export default defineEventHandler(async (event) => {
  const config = useRuntimeConfig(event);
  const { account } = useAppwriteAdminClient(event);

  try {
    const redirectUrl = await account.createOAuth2Token(
      'github',
      `${config.public.api.url}/oauth`,
      `${config.public.api.url}/login`,
      ['read:user', 'user:email']
    );

    return redirectUrl;
  } catch (error) {
    console.log('OAUTH ERROR', error);
  }
});
TypeScript
export default defineEventHandler(async (event) => {
  const { userId, secret } = getQuery<{ userId: string; secret: string }>(
    event
  );

  if (!userId || !secret) {
    return await sendRedirect(event, '/login');
  }

  const config = useRuntimeConfig(event);
  const { account } = useAppwriteAdminClient(event);

  try {
    const session = await account.createSession(userId, secret);
    console.log('SESSION', session);
    const cookieName = APPWRITE_COOKIE_NAME;

    setCookie(event, cookieName, session.secret, {
      domain: config.public.app.url,
      expires: new Date(session.expire),
      path: '/',
      httpOnly: true,
      secure: true,
      sameSite: 'strict'
    });

    return await sendRedirect(event, '/dashboard');
  } catch (error) {
    console.log(error);
  }
});

logs in the screenshot

thank you

TL;DR
Issue: `providerUid` in the session response is an empty string when trying to get the user `uid` from GitHub in a Nuxt app using node-appwrite. Solution: - Check the appwrite version compatibility with the current setup. - Ensure proper configuration for OAuth2 token creation with GitHub. - Verify the correct usage of `createSession` method to fetch the user session details. - Review the session data and handling to ensure providerUid is populated correctly. Remember to validate the setup, configurations, and usage for proper retrieval of `providerUid` in the session response.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more