Skip to content

Commit 26e15f7

Browse files
committed
feat: health endpoint
1 parent f613326 commit 26e15f7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/lib/config/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const kindeConfiguration = {
1212
scope: env.KINDE_SCOPE,
1313
clientSecret: env.KINDE_CLIENT_SECRET,
1414
loginRedirectURL: env.KINDE_POST_LOGIN_REDIRECT_URL,
15-
authUsePKCE: [true, 'true'].includes(env.KINDE_AUTH_WITH_PKCE)
15+
authUsePKCE: [true, 'true'].includes(env.KINDE_AUTH_WITH_PKCE),
16+
debug: env.KINDE_DEBUG || process.env.NODE_ENV !== 'production'
1617
};
1718

1819
export const kindeAPIConfiguration = {

src/lib/handleAuth/handleAuth.ts

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

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

0 commit comments

Comments
 (0)