Modules

@dasporal/svelte-authkit / Exports

@dasporal/svelte-authkit #

Table of contents #

Variables #

Functions #

Variables #

isAuthenticated #

Const isAuthenticated: Writable<boolean>

Defined in #

src/lib/stores/userStore.js:4


user #

Const user: Writable<null>

Defined in #

src/lib/stores/userStore.js:3

Functions #

AuthkitCallback #

AuthkitCallback(params): Promise<Response>

Asynchronous function that handles the callback from the WorkOS authentication process and returns to the homepage.

Parameters #

NameTypeDescription
paramsObjectAn object containing the necessary parameters to handle the callback.
params.secretUint8ArrayThe secret used to sign the JWT.
params.urlURLThe URL containing the code parameter.
params.workOSClientIdstringThe WorkOS client ID.
params.workosWorkOSThe instance of the WorkOS object.

Returns #

Promise<Response>

A new instance of the Response object. This response contains a 302 status and the root URL ("/") in the “Location” header.

Example

const response = await AuthkitCallback({
    workOSClientId: 'env_workos_client_id',
    workos: workos_instance,
    secret: secret,
    url: callback_url
});

Defined in #

src/lib/utils/server/hooks.ts:65


AuthkitSignIn #

AuthkitSignIn(params): Promise<Response>

Asynchronous function that generates an authorization URL and Response for a WorkOS client.

Parameters #

NameTypeDescription
paramsObjectAn object containing the necessary parameters to generate the authorization URL.
params.workOSClientIdstringThe WorkOS client ID.
params.workOSRedirectURIstringThe redirect URI after successful authentication.
params.workosWorkOSThe instance of the WorkOS object.

Returns #

Promise<Response>

A new instance of the Response object. This response contains a 200 status and the authorization URL in the “Location” header.

Example

const response = await AuthkitSignIn({
    workOSClientId: 'your_workos_client_id',
    workOSRedirectURI: 'your_redirect_uri',
    workos: your_workos_instance
});

Defined in #

src/lib/utils/server/hooks.ts:23


AuthkitSignOut #

AuthkitSignOut(): Promise<Response>

Asynchronous function that handles the sign out process from the WorkOS authentication.

Returns #

Promise<Response>

A new instance of the Response object. This response contains a 302 status and the root URL ("/") in the “Location” header, indicating a successful sign out.

Example

const response = await AuthkitSignOut();

Defined in #

src/lib/utils/server/hooks.ts:185


AuthkitVerifyToken #

AuthkitVerifyToken(params): Promise<Response>

Asynchronous function that verifies the stored token containing user inforomations.

Parameters #

NameTypeDescription
paramsObjectAn object containing the necessary parameters to verify the token.
params.eventRequestEvent<Partial<Record<string, string>>, null | string>The RequestEvent containing the token.
params.secretUint8ArrayThe instance of the WorkOS object.

Returns #

Promise<Response>

A new instance of the Response object. This response contains the verification status and the decoded token if the user is logged in, otherwise it will return isAuthenticated with a false value.

Example

const response = await AuthkitVerifyToken({
    event: event,
    secret: secret
});

Defined in #

src/lib/utils/server/hooks.ts:125


initWorkOS #

initWorkOS(WORKOS_API_KEY): WorkOS

Returns a new instance of the WorkOS object.

Parameters #

NameType
WORKOS_API_KEYstring

Returns #

WorkOS

A new instance of the WorkOS object.

Example

const workos = initWorkOS('env_workos_api_key');

Defined in #

src/lib/utils/server/workos.ts:12


signIn #

signIn(): Promise<void>

Asynchronous function that initiates the sign in process.

This function sends a GET request to the ‘/auth’ endpoint and redirects the user to the location specified in the response headers.

Returns #

Promise<void>

Example

await signIn();

Defined in #

src/lib/utils/client/auth.ts:11


signOut #

signOut(): Promise<void>

Asynchronous function that initiates the sign out process.

This function sends a POST request to the ‘/auth/sign-out’ endpoint and redirects the user to the homepage upon successful sign out.

Returns #

Promise<void>

Example

await signOut();

Defined in #

src/lib/utils/client/auth.ts:26


verifyToken #

verifyToken(): Promise<null>

Asynchronous function that verifies the user’s token.

This function sends a POST request to the ‘/auth/verify-token’ endpoint. If the response is OK, it updates the isAuthenticated and user stores with the data received from the response. If the response is not OK, it logs an error message with the response status. If an error occurs during the fetch operation, it logs an error message with the error.

Returns #

Promise<null>

Example

await verifyToken();

Defined in #

src/lib/utils/client/auth.ts:43