#Discord OAuth on Nuxt
100 messages · Page 1 of 1 (latest)
Is this still up to date? Seems there are multiple mistakes in the guide? Eg. wrong file names, functions that dont take arguments but the code here does. Functions missing completely? Am I doing something wrong??
<@&1319717958645452800>?
Expanding on what is not working would be extremely helpful, I'm not a nuxt expert but if you can tell me what exactly isn't working I can try and help. Error messages, stack traces, etc are beneficial.
nuxt-appwrite looks pretty up-to-date so I'm sure you could use it.
you wouldn't use the appwrite web package but the node-appwrite package since nuxt, by default, does SSR you would need the server side package.
There are many cases like this, where file names don’t match at all, exist multiple times with the exact opposite of the code’s function, or contain TypeScript expressions in supposedly pure JavaScript files.
Additionally I get a error 500 when loading the page:
500
useEvent is not defined
at setup ([REDACTED]/pages/account.js:7:21)
at _sfc_main.setup ([REDACTED]/pages/account.js:34:23)
at callWithErrorHandling ([REDACTED]/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19)
at setupStatefulComponent ([REDACTED]/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7848:25)
at setupComponent ([REDACTED]/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7809:36)
at renderComponentVNode ([REDACTED]/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:645:15)
at renderVNode ([REDACTED]/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:779:14)
at renderComponentSubTree ([REDACTED]/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:730:7)
at renderComponentVNode ([REDACTED]/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:664:12)
at renderVNode ([REDACTED]/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:779:14)
Oh yeah, and none of the links for "demos-for-vue" have anything to do with ssr. And when clicking the link on the "all set" page the github repo that opens up is a 404 (https://github.com/appwrite/demos-for-vue/tree/main/server-side-rendering)
I'll forward this along to the appwrite team so they can be aware of the issues with the tutorial
*Edit: I found the sourcecode on a different branch, but it doesn't work (error 500 again) -> https://github.com/appwrite/demos-for-vue/tree/feat-ssr/server-side-rendering
Demos and tutorials for getting started with Appwrite + Vue.js - appwrite/demos-for-vue
Thanks!
I'm wondering if they know there are issues since I'm not seeing this tutorial on the main tutorials page. Nevertheless it should be fixed or removed entirely imo.
I hope that there is some way that it gets updates 
I think for the time being, you could just not use middleware, and check auth on each page. Remove any sort of typings. Lastly, fix the naming of the second occurance of oauth.post.js to oauth.get.js
Hmm, you mean just using the client side version?
Here are the fixes I made that got it working
-
fix the env reference in the server/lib/appwrite.ts file. It should be PUBLIC_APPWRITE_ENDPOINT, and PUBLIC_APPWRITE_PROJECT_ID. Also since these are undefined you need to have a check, so I just did || "" for now.
-
Switch from using useEvent(), to using useRequestEvent()
Let me know if this helps any.
Yes, that kind of works. Now I only have one more error from h3:
ℹ Error: Cannot set headers after they are sent to the client
⁃ at ServerResponse.setHeader (node:_http_outgoing:655:11)
⁃ at sendRedirect ([REDACTED]/node_modules/h3/dist/index.mjs:782:18)
⁃ at Object.handler ([REDACTED]/server/routes/index.js:6:1)
1 ┃ export default defineEventHandler(async (event) => {
2 ┃ if (event.context.user) {
3 ┃ await sendRedirect(event, "/account");
4 ┃ }
5 ┃
❯ 6 ┃ await sendRedirect(event, "/signup");
7 ┃ });
8 ┃
⁃ at runNextTicks (node:internal/process/task_queues:60:5)
⁃ at process.processImmediate (node:internal/timers:454:9)
⁃ at process.callbackTrampoline (node:internal/async_hooks:130:17)
⁃ (async file:///[REDACTED]/node_modules/h3/dist/index.mjs:2009:19)
⁃ at async Object.callAsync ([REDACTED]/node_modules/unctx/dist/index.mjs:72:16)
⁃ at async Server.toNodeHandle ([REDACTED]/node_modules/h3/dist/index.mjs:2301:7)
[CAUSE]
Error {
stack: 'Cannot set headers after they are sent to the client\n' +
' at ServerResponse.setHeader (node:_http_outgoing:655:11)\n' +
'at sendRedirect ([REDACTED]/node_modules/h3/dist/index.mjs:782:18)\n' +
'at Object.handler ([REDACTED]/server/routes/index.js:6:1)\n' +
' at runNextTicks (node:internal/process/task_queues:60:5)\n' +
' at process.processImmediate (node:internal/timers:454:9)\n' +
' at process.callbackTrampoline (node:internal/async_hooks:130:17)\n' +
'at async file:///[REDACTED]/node_modules/h3/dist/index.mjs:2009:19)\n' +
'at async Object.callAsync ([REDACTED]/node_modules/unctx/dist/index.mjs:72:16)\n' +
'at async Server.toNodeHandle ([REDACTED]/node_modules/h3/dist/index.mjs:2301:7)',
message: 'Cannot set headers after they are sent to the client',
code: 'ERR_HTTP_HEADERS_SENT',
}
hmmm yea, I honestly know nothing about that lol I'll see if I can find anything.
Yeah, i'll try later if i can find a fix
This seemed to fix it for me
export default defineEventHandler(async (event) => {
if (event.context.user) {
return await sendRedirect(event, "/account");
}
return await sendRedirect(event, "/signin");
});
Yeah, got it aswell, I just moved it into an else. But now (before aswell) the values pop up for a split second and then disappear followed by another error:
Yea, I think this error is because there is no type defined for the context
I think it has something to do with this
import type { Models } from "node-appwrite";
declare module "h3" {
interface H3EventContext {
user?: Models.User<Models.Preferences<any>>;
}
}
You can try something like this
const event = useRequestEvent()
const user = event?.context?.user
Instead of doing object destructuring
yeah, at least i dont get an error now.
but still the values disappear after the page fully loads
And when I logg out I get the following error:
500
User (role: guests) missing scope (account)
at _Client.call ([REDACTED]/esc/node_modules/node-appwrite/src/client.ts:354:9)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.handler ([REDACTED]/esc/server/api/signout.post.js:7:1)
at async file:///[REDACTED]/esc/node_modules/h3/dist/index.mjs:2009:19)
at async Object.callAsync ([REDACTED]/esc/node_modules/unctx/dist/index.mjs:72:16)
at async Server.toNodeHandle ([REDACTED]/esc/node_modules/h3/dist/index.mjs:2301:7)
really.. hmm.. I'm not running into that issue
could be something with the sessions
Yea, it looks like your session is being removed for some reason
I forked the repo from above and made my changes to it, so maybe you could be missing something?
could be?
Does this make sense? Doesn't this need to be the url of my website?
shouln't that work?
What is the website URL you're using
Yea, it would be your websites url
Thats event origin => localhost:3000
i think it includes http actually
can you check the console.log?
jep
Yes, else the ${} wouldn't work
alright in the ss it wasn't so just verifying
where is input coming from? Could the invalid URL not even be one of the two you put in but something else?
i dont think thats from me, only the "discord" from the provider
could it be the admin client not initializing correctly?
omg
i know why...
(my .env)
my appwrite.js
...
Whoops
#1355291187484819605 message
:P
at least the other stuff should be fixed now
Cool beans, glad you're making some headway
okay. i'm officially loosing my mind.
So you authenticated and now the context is empty of user data?
can you see what is triggering that?
As soon as the page fully loads the content disappears
oohh
but that kind of proofs the exact opposite behavior
it's changing somewhere on the client for some reason. for the server it's still the old value tho
What does your code for this page loo like
<!-- pages/account.vue -->
<script setup>
const event = useRequestEvent()
// console.log(event?.context)
const user = event?.context?.user
</script>
<template>
<ul>
<li>
<strong>Email:</strong> {{ user?.email }}
</li>
<li>
<strong>Name:</strong> {{ user?.name }}
</li>
<li>
<strong>ID: </strong> {{ user?.$id }}
</li>
</ul>
<form method="post" action="/api/signout">
<button type="submit">Log out</button>
</form>
</template>
the console log gives me the right user info tho
I don't know what exacly is going on here. but imma go to bed now. Its like 11pm rn. I'll try again tomorrow. Thanks tho!

try this
<script setup>
const event = useRequestEvent();
const user = useState("user", () => event?.context?.user);
</script>
<template>
<ul>
<li>
<strong>Email:</strong> {{ user?.email }}
</li>
<li>
<strong>Name:</strong> {{ user?.name }}
</li>
<li>
<strong>ID: </strong> {{ user?.$id }}
</li>
</ul>
<form method="post" action="/api/signout">
<button type="submit">Log out</button>
</form>
</template>
Works after reloading the page, but not after loading from the oauth.get page directly
Any ideas?
Sorry I hadn't had the opportunity to look more into it
I'm not personally able to recreate the behavior you're experiencing so I'm not sure the best thing to do
Do you have any sort of error logs or anything?
Seems like there is no error at all. The user object just returns undefined until reloading.
Hmm it seems nuxt isn’t taking into account the cookie values set until after reload. I’m not sure why, can you check in the middleware when it’s getting the user if that’s null or undefined? Maybe a console log?
I dont quite understand. Where exacly should I put the log?
// server/middleware/auth.js
import { createSessionClient } from "../lib/appwrite";
export default defineEventHandler(async (event) => {
const { account } = createSessionClient(event);
try {
event.context.user = await account.get();
} catch (error) {}
});
yea here log account and see if it's just undefined?
Before reload:
auth middleware Account {
client:
_Client {
config:
{ endpoint: '[REDACTED - APPWRITE_ENDPOINT]',
selfSigned: false,
project: '[REDACTED - APPWRITE_PROJECT]',
key: '',
jwt: '',
locale: '',
session: '',
forwardeduseragent: '' },
headers:
{ 'x-sdk-name': 'Node.js',
'x-sdk-platform': 'server',
'x-sdk-language': 'nodejs',
'x-sdk-version': '15.0.1',
'user-agent': 'AppwriteNodeJSSDK/15.0.1 (win32; x64) Node.js/v20.19.0',
'X-Appwrite-Response-Format': '1.6.0',
'X-Appwrite-Project': '[REDACTED - APPWRITE_PROJECT]' } } }
After reload:
auth middleware Account {
client:
_Client {
config:
{ endpoint: '[REDACTED - APPWRITE_ENDPOINT]',
selfSigned: false,
project: '[REDACTED - APPWRITE_PROJECT]',
key: '',
jwt: '',
locale: '',
session:
'eyJpZCI6IjY3ZTZmMTVlOTY4NjVlYTZkNjZmIiwic2VjcmV0IjoiMTdlYjZiOTcxMGIzNTY5OTVhOWRlZjQzMmYwOTIyODhhNzYxNDZkZDk0NzIyNjU3ZThmOGQ0ZDgyZDk4NTVhODUxNmJlOWNlZWM5NTFhOWQwOWMzNGIwMTA3OGY0NGFhNmZmNDU3MzRhZjgwM2EyOTI5MDJlYTQ0ZDcyZjg4MWYzOTcxYTVlNTJkNGEwOTZhNmMzMDA4ZDdkZTQ4OWZkOWQ5MGJjOWNkZjI2NGJiMDcyMzQ2NjdlMTFmY2I2ZDZjNWMzYWJjMGNmZjZhMWU5NTk5MGE2ZTU1NGNlNWYzZDc4OTBkN2NlNjY5YzJkMjgwZWQ1NDY4YjI2YWUzYWRjZCJ9',
forwardeduseragent: '' },
headers:
{ 'x-sdk-name': 'Node.js',
'x-sdk-platform': 'server',
'x-sdk-language': 'nodejs',
'x-sdk-version': '15.0.1',
'user-agent': 'AppwriteNodeJSSDK/15.0.1 (win32; x64) Node.js/v20.19.0',
'X-Appwrite-Response-Format': '1.6.0',
'X-Appwrite-Project': '[REDACTED - APPWRITE_PROJECT]',
'X-Appwrite-Session':
'eyJpZCI6IjY3ZTZmMTVlOTY4NjVlYTZkNjZmIiwic2VjcmV0IjoiMTdlYjZiOTcxMGIzNTY5OTVhOWRlZjQzMmYwOTIyODhhNzYxNDZkZDk0NzIyNjU3ZThmOGQ0ZDgyZDk4NTVhODUxNmJlOWNlZWM5NTFhOWQwOWMzNGIwMTA3OGY0NGFhNmZmNDU3MzRhZjgwM2EyOTI5MDJlYTQ0ZDcyZjg4MWYzOTcxYTVlNTJkNGEwOTZhNmMzMDA4ZDdkZTQ4OWZkOWQ5MGJjOWNkZjI2NGJiMDcyMzQ2NjdlMTFmY2I2ZDZjNWMzYWJjMGNmZjZhMWU5NTk5MGE2ZTU1NGNlNWYzZDc4OTBkN2NlNjY5YzJkMjgwZWQ1NDY4YjI2YWUzYWRjZCJ9' } } }
seems like the createSessionClient doesn't even have anything in the event at that time
but oauth.get.js does.
This makes no sense at all....
id suspect it's because it is not aware of the new cookie that was set on the server
i don't know what the fix would be
clould be..
did you hear anything from the appwrite devs?
no /:

