K
Kinde•11mo ago
peppermint

Problem with the SvelteKit SDK.

Hi! I tried to integrate Kinde with my exiting Sveltekit 2 project, I have followed the official documentation here https://kinde.com/docs/developer-tools/sveltekit-sdk/ . But everytime I visted the /api/auth/login and /api/auth/register the server returned 500 error and this is what was shown in the server terminal. I have no idea why this error occurred.
Kinde Docs
SvelteKit SDK - Developer tools - Help center
Our developer tools provide everything you need to get started with Kinde.
From An unknown user
From An unknown user
No description
No description
No description
No description
4 Replies
onderay
onderay•11mo ago
We have sessionStorage exported. So, can you use sessionStorage.getItem() and see if that works for you?
peppermint
peppermintOP•11mo ago
Thank you, I'll let you know the result. I works as expected, thank you. One more thing, I want to integrate Kinde with a Laravel backend but only serve as an API only and will receive auth token or a JWT from the authenticated frontend. Is it possible?
onderay
onderay•11mo ago
I suspect I might have answered this somewhere else for you 🤔 Yes, it's possible to integrate Kinde with a Laravel backend that serves as an API. The SvelteKit frontend can handle the authentication using Kinde, and then pass the JWT or auth token to the Laravel backend for subsequent requests. Here's a general idea of how you can do it: In your SvelteKit frontend, you can use the Kinde SvelteKit SDK to handle the authentication. The SDK provides methods to handle login, logout, and also to check if a user is authenticated. You can find more details in the SvelteKit SDK documentation. Once the user is authenticated, you can get the access token using the getToken method provided by the SDK. This token is what you'll send to your Laravel backend. In your Laravel backend, you'll need to verify the token in each request to ensure it's valid. You can do this by checking the token against the Kinde issuer URL and the audience (which should be your Laravel API). Remember, the token should be sent in the Authorization header of your requests to the Laravel API. Here's an example of how you can do this:
javascript
const {getToken} = useKindeAuth();
const accessToken = await getToken();
const res = await fetch(`https://api.myapp.com/books`, {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
javascript
const {getToken} = useKindeAuth();
const accessToken = await getToken();
const res = await fetch(`https://api.myapp.com/books`, {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
Please note that this is a general guide and you might need to adjust based on your specific use case and setup. If you need more detailed help, feel free to ask!
peppermint
peppermintOP•11mo ago
Yea sorry, I was the one reach out through intercom😆 Thanks anyway
Want results from more Discord servers?
Add your server