Skip to content

Commit b53bfa2

Browse files
committed
Merge branch 'main' into fix/redirect-on-login
2 parents 5683543 + a5877bb commit b53bfa2

File tree

6 files changed

+51
-7
lines changed

6 files changed

+51
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The Kinde SDK for SvelteKit.
44

5-
[![PRs - Welcome](https://img.shields.io/badge/PRs-Welcome-green?style=for-the-badge)](https://kinde.com/docs/developer-tools) [![Kinde - Docs](https://img.shields.io/badge/Kinde-Docs-white?style=for-the-badge)](https://kinde.com/docs/developer-tools) [![Kinde Community](https://img.shields.io/badge/Slack-4A154B?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/thekindecommunity/shared_invite/zt-26hdaavyc-CfOa06vP23guSwK~~OpFMQ) [![Discord](https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/wHX6j7wG5d)
5+
[![PRs - Welcome](https://img.shields.io/badge/PRs-Welcome-green?style=for-the-badge)](https://kinde.com/docs/developer-tools) [![Kinde - Docs](https://img.shields.io/badge/Kinde-Docs-white?style=for-the-badge)]([https://kinde.com/docs/developer-tools](https://kinde.com/docs/developer-tools/sveltekit-sdk/)) [![Kinde Community](https://img.shields.io/badge/Slack-4A154B?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/thekindecommunity/shared_invite/zt-26hdaavyc-CfOa06vP23guSwK~~OpFMQ) [![Discord](https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/wHX6j7wG5d)
66

77
## Development
88

@@ -83,6 +83,7 @@ KINDE_SCOPE=profile email offline openid
8383
KINDE_USER_EMAIL_TEST= // An user has existed in your organization
8484
KINDE_USER_PASSWORD_TEST=
8585
KINDE_AUTH_WITH_PKCE= // Set `true` if you want to use Authentication Code Flow with PKCE
86+
KINDE_DEBUG= // Set `true` if you want to enable the `api/auth/health` endpoint
8687
```
8788
8889
Finally, you can simply run the command

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"svelte": "^4.0.0"
4545
},
4646
"dependencies": {
47-
"@kinde-oss/kinde-typescript-sdk": "^2.4.0"
47+
"@kinde-oss/kinde-typescript-sdk": "^2.6.2"
4848
},
4949
"devDependencies": {
5050
"@playwright/test": "^1.28.1",

src/lib/config/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
22
// @ts-nocheck
33
import {env} from '$env/dynamic/private';
4+
import {version} from '$app/environment';
45

56
export const kindeConfiguration = {
67
authDomain: env.KINDE_ISSUER_URL,
@@ -12,11 +13,14 @@ export const kindeConfiguration = {
1213
scope: env.KINDE_SCOPE,
1314
clientSecret: env.KINDE_CLIENT_SECRET,
1415
loginRedirectURL: env.KINDE_POST_LOGIN_REDIRECT_URL,
15-
authUsePKCE: [true, 'true'].includes(env.KINDE_AUTH_WITH_PKCE)
16+
authUsePKCE: [true, 'true'].includes(env.KINDE_AUTH_WITH_PKCE),
17+
debug: env.KINDE_DEBUG || process.env.NODE_ENV !== 'production'
1618
};
1719

1820
export const kindeAPIConfiguration = {
1921
audience: `${env.KINDE_ISSUER_URL}/api`,
2022
clientId: env.KINDE_CLIENT_ID,
21-
clientSecret: env.KINDE_CLIENT_SECRET
23+
clientSecret: env.KINDE_CLIENT_SECRET,
24+
framework: 'Sveltekit',
25+
frameworkVersion: version
2226
};

src/lib/handleAuth/handleAuth.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {sessionStorage} from '$lib/sessionStorage/sessionStorage.js';
44
import {parseSearchParamsToObject} from '$lib/utils/index.js';
55
import type {SessionManager} from '@kinde-oss/kinde-typescript-sdk';
66
import {error, redirect, type RequestEvent} from '@sveltejs/kit';
7+
import {version} from '$app/environment';
78

89
const KEY_POST_LOGIN_REDIRECT_URL = 'post-login-redirect-url';
910

@@ -19,6 +20,32 @@ export async function handleAuth({
1920
storePostLoginRedirectUrl(options);
2021
url = await kindeAuthClient.login(request as unknown as SessionManager, options);
2122
break;
23+
case 'health':
24+
if (!kindeConfiguration.debug) {
25+
url = new URL(kindeConfiguration.loginRedirectURL);
26+
break;
27+
}
28+
return new Response(
29+
JSON.stringify({
30+
authDomain: kindeConfiguration.authDomain || '',
31+
clientId: kindeConfiguration.clientId || '',
32+
logoutRedirectURL: kindeConfiguration.logoutRedirectURL || '',
33+
redirectURL: kindeConfiguration.redirectURL || '',
34+
audience: kindeConfiguration.audience || '',
35+
scope: kindeConfiguration.scope || '',
36+
clientSecret: kindeConfiguration.clientSecret.match('[a-z0-9]{32}')
37+
? 'Set correctly'
38+
: 'Not set correctly',
39+
loginRedirectURL: kindeConfiguration.loginRedirectURL || '',
40+
authUsePKCE: kindeConfiguration.authUsePKCE,
41+
version: version,
42+
framework: 'sveltekit'
43+
}),
44+
{
45+
status: 200,
46+
headers: {'Content-Type': 'application/json'}
47+
}
48+
);
2249
case 'register':
2350
storePostLoginRedirectUrl(options);
2451
url = await kindeAuthClient.register(request as unknown as SessionManager, options);

src/routes/+page.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
<h1>Welcome to SvelteKit</h1>
2-
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
1+
<script>
2+
import {version} from '$app/environment';
3+
</script>
4+
5+
<h1>Welcome to Kinde Svelte SDK v{version}</h1>

svelte.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import adapter from '@sveltejs/adapter-auto';
22
import { vitePreprocess } from '@sveltejs/kit/vite';
3+
import { readFileSync } from 'fs';
4+
import { fileURLToPath } from 'url';
5+
6+
const file = fileURLToPath(new URL('package.json', import.meta.url));
7+
const json = readFileSync(file, 'utf8');
8+
const pkg = JSON.parse(json);
39

410
/** @type {import('@sveltejs/kit').Config} */
511
const config = {
@@ -11,7 +17,10 @@ const config = {
1117
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
1218
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
1319
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
14-
adapter: adapter()
20+
adapter: adapter(),
21+
version: {
22+
name: pkg.version,
23+
}
1524
}
1625
};
1726

0 commit comments

Comments
 (0)