clerk-solidjs
Version:
63 lines (58 loc) • 2.36 kB
text/typescript
import { AuthObject, VerifyTokenOptions } from '@clerk/backend';
import { RequestMiddleware } from '@solidjs/start/middleware';
import { MultiDomainAndOrProxy, SignInForceRedirectUrl, SignInFallbackRedirectUrl, SignUpForceRedirectUrl, SignUpFallbackRedirectUrl, LegacyRedirectProps } from '@clerk/types';
type AuthHelper = () => AuthObject;
/**
* Function that retrieves the authentication information from the event object.
* You must implement `clerkMiddleware` to use this function.
*
* Must be called from within a server function.
*
* @example
* async function myServerFunction() {
* 'use server';
* const { userId } = auth();
* // ...
* }
*
* @return The authentication information stored in the event object.
*/
declare const auth: AuthHelper;
type LoaderOptions = {
publishableKey?: string;
jwtKey?: string;
secretKey?: string;
authorizedParties?: [];
signInUrl?: string;
signUpUrl?: string;
} & Pick<VerifyTokenOptions, 'audience'> & MultiDomainAndOrProxy & SignInForceRedirectUrl & SignInFallbackRedirectUrl & SignUpForceRedirectUrl & SignUpFallbackRedirectUrl & LegacyRedirectProps;
/**
* Returns a middleware function that authenticates a request using Clerk.
* This injects the auth object into Solid Start's RequestEventLocals.
*
* After implementing this middleware you can access the auth object from `RequestEvent.locals`,
* or using the `auth()` helper function.
*
* You must define Solid Start middleware. See {@link https://docs.solidjs.com/solid-start/advanced/middleware}
*
* @param {LoaderOptions} options - The options for creating a Clerk client.
* @return {RequestMiddleware} A middleware function that authenticates a request using Clerk.
* @throws {Error} Throws an error if there is an unexpected handshake without a redirect.
*
* @example
* ```ts
* import { createMiddleware } from "@solidjs/start/middleware";
* import { clerkMiddleware } from 'clerk-solidjs/start/server';
*
* export default createMiddleware({
* onRequest: [
* clerkMiddleware({
* publishableKey: import.meta.env.VITE_CLERK_PUBLISHABLE_KEY,
* secretKey: import.meta.env.CLERK_SECRET_KEY,
* }),
* ],
* });
* ```
*/
declare const clerkMiddleware: (options?: LoaderOptions) => RequestMiddleware;
export { type AuthHelper as A, auth as a, clerkMiddleware as c };