Back

ProviderAccessToken, ProviderUid is empty after creating session using Github Oauth

  • 0
  • Web
Zubi🌟
2 Aug, 2024, 00:35

When i get the loggedInUser it returns user but when try to get a session using this ``` "use server"; import { Client, Account } from "node-appwrite"; import { cookies } from "next/headers";

export async function createSessionClient() { const client = new Client() .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!) .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT!);

TypeScript
const session = cookies().get("my-custom-session");
if (!session || !session.value) {
    throw new Error("No session");
}

client.setSession(session.value);

return {
    get account() {
        return new Account(client);
    },
};

}

export async function createAdminClient() { const client = new Client() .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!) .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT!) .setKey(process.env.NEXT_APPWRITE_KEY!);

TypeScript
return {
    get account() {
        return new Account(client);
    },
};

}

export async function getLoggedInUser() { try { const { account } = await createSessionClient(); return await account.get(); } catch (error) { return null; } }

export async function getLoggedInSession() { try { const { account } = await createSessionClient(); return await account.getSession('current'); } catch (error) { return null; } }```

the session which is return has null provider access token

TypeScript
Session {
  '$id': '66ac26d5de54d1',
  '$createdAt': '2024-08-02T00:22:45.924+00:00',
  '$updatedAt': '2024-08-02T00:22:45.924+00:00',
  userId: '66aaa7d01f8d4af',
  expire: '2025-08-02T00:22:45.910+00:00',
  provider: 'oauth2',
  providerUid: '',
  providerAccessToken: '',
  providerAccessTokenExpiry: '',
  providerRefreshToken: '', } ```

Followed this guide carefully 
https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-1
TL;DR
Issue: When creating a session using Github OAuth in a Node.js app, session's ProviderAccessToken and ProviderUid are empty. Solution: There is a known issue related to this problem: https://github.com/appwrite/appwrite/issues/8206. A fix or workaround might be provided on the issue thread.
Steven
2 Aug, 2024, 00:46
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