Skip to content

Commit

Permalink
feat: health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRivers committed Mar 1, 2024
1 parent f613326 commit 26e15f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ KINDE_SCOPE=profile email offline openid
KINDE_USER_EMAIL_TEST= // An user has existed in your organization
KINDE_USER_PASSWORD_TEST=
KINDE_AUTH_WITH_PKCE= // Set `true` if you want to use Authentication Code Flow with PKCE
KINDE_DEBUG= // Set `true` if you want to enable the `api/auth/health` endpoint
```
Finally, you can simply run the command
Expand Down
3 changes: 2 additions & 1 deletion src/lib/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const kindeConfiguration = {
scope: env.KINDE_SCOPE,
clientSecret: env.KINDE_CLIENT_SECRET,
loginRedirectURL: env.KINDE_POST_LOGIN_REDIRECT_URL,
authUsePKCE: [true, 'true'].includes(env.KINDE_AUTH_WITH_PKCE)
authUsePKCE: [true, 'true'].includes(env.KINDE_AUTH_WITH_PKCE),
debug: env.KINDE_DEBUG || process.env.NODE_ENV !== 'production'
};

export const kindeAPIConfiguration = {
Expand Down
27 changes: 27 additions & 0 deletions src/lib/handleAuth/handleAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {kindeConfiguration} from '$lib/index.js';
import {parseSearchParamsToObject} from '$lib/utils/index.js';
import type {SessionManager} from '@kinde-oss/kinde-typescript-sdk';
import {error, redirect, type RequestEvent} from '@sveltejs/kit';
import {version} from '$app/environment';

export async function handleAuth({
request,
Expand All @@ -15,6 +16,32 @@ export async function handleAuth({
case 'login':
url = await kindeAuthClient.login(request as unknown as SessionManager, options);
break;
case 'health':
if (!kindeConfiguration.debug) {
url = new URL(kindeConfiguration.loginRedirectURL);
break;
}
return new Response(
JSON.stringify({
authDomain: kindeConfiguration.authDomain || '',
clientId: kindeConfiguration.clientId || '',
logoutRedirectURL: kindeConfiguration.logoutRedirectURL || '',
redirectURL: kindeConfiguration.redirectURL || '',
audience: kindeConfiguration.audience || '',
scope: kindeConfiguration.scope || '',
clientSecret: kindeConfiguration.clientSecret.match('[a-z0-9]{32}')
? 'Set correctly'
: 'Not set correctly',
loginRedirectURL: kindeConfiguration.loginRedirectURL || '',
authUsePKCE: kindeConfiguration.authUsePKCE,
version: version,
framework: 'sveltekit'
}),
{
status: 200,
headers: {'Content-Type': 'application/json'}
}
);
case 'register':
url = await kindeAuthClient.register(request as unknown as SessionManager, options);
break;
Expand Down

0 comments on commit 26e15f7

Please sign in to comment.