API Authentication not working
Hey, its me again.
Okay so i followed the sapphire docs and made the authenticated precondition be
and i make the api call to refresh/fetch a user from the endpoint users/@me but i get
{ error: "Cannot read properties of null (reading 'id')" }
when i log the response data returned here so that means auth
is null? i have credentials: 'include'
in the request thoSolution:Jump to solution
@Oreo ™ Try using the
fetch
on the event
object from the params. It's SvelteKit's special fetch that can include credentials and such.
```ts
import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {...17 Replies
I just struggle with oauth api stuff
Wild shot while being half awake but can you ditch the class with statics and just export functions? If you want to group them still you can use a namespace
namespace ApiClient {
export function aaa() { }
}
and when you go to the devtools -> application -> cookies you can see your auth cookie there?
also is the domain correct? if you use
api.oreotm.xyz
then Domain
should be .oreotm.xyz
. Mind that leading .
yup i see CARDINAL_AUTH and the domain is .oreotm.xyz
https://stackoverflow.com/questions/34558264/fetch-api-with-cookie
This said use
'same-origin'
but nothing changedStack Overflow
Fetch API with Cookie
I am trying out the new Fetch API but is having trouble with Cookies. Specifically, after a successful login, there is a Cookie header in future requests, but Fetch seems to ignore that headers, an...
the endpoint works fine
its just that the cookie isnt sent through
ok so i found a "fix"
but aint no way this is acceptable
why doesnt credentials: 'include' just work
Didn't get back to you before on this. Is your bot open source? And does it work when running through
127.0.0.1
in dev?GitHub
cardinal-bot/src/config.ts at e6fcdf38c40eae0672c60387f49084977ad15...
Contribute to TheOreoTM/cardinal-bot development by creating an account on GitHub.
@Helpers btw if anyoen can help oreo
Solution
@Oreo ™ Try using the
fetch
on the event
object from the params. It's SvelteKit's special fetch that can include credentials and such.
Relevant docs: https://kit.svelte.dev/docs/load#making-fetch-requests
SvelteKit docs
Loading data • SvelteKit documentation