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
- User ID case sensitivity
I see that through REST (and SDK as well), getting a user is not case sensitive. And even though documentation does not clearly state that it is, the wording "V...
- Any way to temporarily bypass the email ...
Hey guys, any way to bypass the email verification to use the accounts again? i need to recover some projects that due to recent changes have been stopped, and ...
- How to use Sites on selfhosted appwrite
whenever I try to create a site even with template it says 404 nginx error