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.Recommended threads
- HUGE OUTRAGE IN APPWRITE, I CANNOT ACCES...
I have 2k users trying to access, sending me messages. What am I supposed to do? Please solve this asap.
- All my apps are not opening now
All my apps are not opening now 200+ apps are not opening plz fast
- Failed to generate functions SSL
```appwrite-worker-certificates | Cannot renew domain (functions.domain.com) on attempt no. 9 certificate: Failed to verify domain DNS records. appwrite-worker...