@ouim/logto-authkit 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=(s="vite")=>{const t={jose:"jose/dist/node/cjs"};switch(s){case"vite":return{optimizeDeps:{include:["@logto/react"]},resolve:{alias:t}};case"webpack":case"nextjs":return{resolve:{alias:t}};default:return{alias:t}}},n=e("vite"),o=e("webpack"),i=e("nextjs");exports.getBundlerConfig=e;exports.nextjsConfig=i;exports.viteConfig=n;exports.webpackConfig=o;
@@ -0,0 +1,81 @@
1
+ interface BundlerConfig {
2
+ optimizeDeps?: {
3
+ include: string[];
4
+ };
5
+ resolve?: {
6
+ alias: Record<string, string>;
7
+ };
8
+ alias?: Record<string, string>;
9
+ }
10
+ /**
11
+ * Bundler Configuration Helper
12
+ *
13
+ * Returns bundler-specific configuration to resolve the jose library correctly.
14
+ * The jose library has different import paths for different environments, and bundlers
15
+ * need proper configuration to handle these correctly.
16
+ *
17
+ * @param {'vite' | 'webpack' | 'nextjs'} [bundler='vite'] - Target bundler type
18
+ *
19
+ * @returns {BundlerConfig} Configuration object for the specified bundler
20
+ *
21
+ * @example
22
+ * // Vite configuration
23
+ * import { getBundlerConfig } from '@ouim/logto-authkit';
24
+ * import { defineConfig } from 'vite';
25
+ *
26
+ * export default defineConfig({
27
+ * ...getBundlerConfig('vite'),
28
+ * // other vite config
29
+ * });
30
+ *
31
+ * @example
32
+ * // Webpack configuration
33
+ * import { getBundlerConfig } from '@ouim/logto-authkit';
34
+ *
35
+ * module.exports = {
36
+ * ...getBundlerConfig('webpack'),
37
+ * // other webpack config
38
+ * };
39
+ *
40
+ * @example
41
+ * // Next.js configuration
42
+ * const { getBundlerConfig } = require('@ouim/logto-authkit');
43
+ *
44
+ * module.exports = {
45
+ * ...getBundlerConfig('nextjs'),
46
+ * // other Next.js config
47
+ * };
48
+ */
49
+ export declare const getBundlerConfig: (bundler?: "vite" | "webpack" | "nextjs") => BundlerConfig;
50
+ /**
51
+ * Vite bundler configuration pre-built for Logto.
52
+ * Use this directly in your vite.config.ts if you don't need custom configuration.
53
+ *
54
+ * @example
55
+ * import { viteConfig } from '@ouim/logto-authkit';
56
+ * import { defineConfig } from 'vite';
57
+ *
58
+ * export default defineConfig({ ...viteConfig });
59
+ */
60
+ export declare const viteConfig: BundlerConfig;
61
+ /**
62
+ * Webpack bundler configuration pre-built for Logto.
63
+ * Use this directly in your webpack.config.js if you don't need custom configuration.
64
+ *
65
+ * @example
66
+ * const { webpackConfig } = require('@ouim/logto-authkit');
67
+ *
68
+ * module.exports = { ...webpackConfig, entry: './src/index.js' };
69
+ */
70
+ export declare const webpackConfig: BundlerConfig;
71
+ /**
72
+ * Next.js bundler configuration pre-built for Logto.
73
+ * Use this directly in your next.config.js if you don't need custom configuration.
74
+ *
75
+ * @example
76
+ * const { nextjsConfig } = require('@ouim/logto-authkit');
77
+ *
78
+ * module.exports = { ...nextjsConfig };
79
+ */
80
+ export declare const nextjsConfig: BundlerConfig;
81
+ export {};
@@ -0,0 +1,31 @@
1
+ const s = (t = "vite") => {
2
+ const e = {
3
+ jose: "jose/dist/node/cjs"
4
+ };
5
+ switch (t) {
6
+ case "vite":
7
+ return {
8
+ optimizeDeps: {
9
+ include: ["@logto/react"]
10
+ },
11
+ resolve: {
12
+ alias: e
13
+ }
14
+ };
15
+ case "webpack":
16
+ case "nextjs":
17
+ return {
18
+ resolve: {
19
+ alias: e
20
+ }
21
+ };
22
+ default:
23
+ return { alias: e };
24
+ }
25
+ }, o = s("vite"), n = s("webpack"), i = s("nextjs");
26
+ export {
27
+ s as getBundlerConfig,
28
+ i as nextjsConfig,
29
+ o as viteConfig,
30
+ n as webpackConfig
31
+ };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { CallbackPageProps } from './types.js';
3
+ export declare const CallbackPage: React.FC<CallbackPageProps>;
@@ -0,0 +1,53 @@
1
+ import type { ButtonProps } from './ui/button.js';
2
+ export interface SignInButtonProps extends Omit<ButtonProps, 'onClick'> {
3
+ /**
4
+ * The text label displayed on the button.
5
+ * @default "Sign In"
6
+ */
7
+ label?: string;
8
+ /**
9
+ * The URL to redirect to after successful sign-in.
10
+ * If not provided, defaults to the AuthProvider's callbackUrl.
11
+ */
12
+ redirectUri?: string;
13
+ /**
14
+ * Whether to use popup sign-in flow instead of redirect.
15
+ * If not provided, defaults to the AuthProvider's enablePopupSignIn setting.
16
+ */
17
+ usePopup?: boolean;
18
+ /**
19
+ * Optional callback to execute before initiating sign-in.
20
+ * Useful for tracking or validation.
21
+ */
22
+ onBeforeSignIn?: () => void | Promise<void>;
23
+ /**
24
+ * Optional callback to execute after sign-in completes.
25
+ * Useful for tracking or post-sign-in logic.
26
+ */
27
+ onAfterSignIn?: () => void | Promise<void>;
28
+ /**
29
+ * Optional callback to execute if sign-in fails.
30
+ */
31
+ onSignInError?: (error: Error) => void;
32
+ }
33
+ /**
34
+ * A simple, reusable button component for initiating the sign-in flow.
35
+ *
36
+ * @example
37
+ * // Basic usage with default settings
38
+ * <SignInButton />
39
+ *
40
+ * @example
41
+ * // With custom props
42
+ * <SignInButton
43
+ * label="Log in to your account"
44
+ * usePopup={true}
45
+ * variant="outline"
46
+ * onAfterSignIn={() => console.log('User signed in!')}
47
+ * />
48
+ *
49
+ * @example
50
+ * // With custom redirect
51
+ * <SignInButton redirectUri="/dashboard" />
52
+ */
53
+ export declare function SignInButton({ label, redirectUri, usePopup, onBeforeSignIn, onAfterSignIn, onSignInError, disabled, ...buttonProps }: SignInButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { type VariantProps } from 'class-variance-authority';
3
+ declare const Alert: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & VariantProps<(props?: ({
4
+ variant?: "default" | "destructive" | null | undefined;
5
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string> & React.RefAttributes<HTMLDivElement>>;
6
+ declare const AlertTitle: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLHeadingElement> & React.RefAttributes<HTMLParagraphElement>>;
7
+ declare const AlertDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
8
+ export { Alert, AlertTitle, AlertDescription };
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import * as AvatarPrimitive from '@radix-ui/react-avatar';
3
+ declare const Avatar: React.ForwardRefExoticComponent<Omit<AvatarPrimitive.AvatarProps & React.RefAttributes<HTMLSpanElement>, "ref"> & React.RefAttributes<HTMLSpanElement>>;
4
+ declare const AvatarImage: React.ForwardRefExoticComponent<Omit<AvatarPrimitive.AvatarImageProps & React.RefAttributes<HTMLImageElement>, "ref"> & React.RefAttributes<HTMLImageElement>>;
5
+ declare const AvatarFallback: React.ForwardRefExoticComponent<Omit<AvatarPrimitive.AvatarFallbackProps & React.RefAttributes<HTMLSpanElement>, "ref"> & React.RefAttributes<HTMLSpanElement>>;
6
+ export { Avatar, AvatarImage, AvatarFallback };
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import { type VariantProps } from 'class-variance-authority';
3
+ declare const badgeVariants: (props?: ({
4
+ variant?: "default" | "destructive" | "outline" | "secondary" | null | undefined;
5
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
6
+ export interface BadgeProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof badgeVariants> {
7
+ }
8
+ declare function Badge({ className, variant, ...props }: BadgeProps): import("react/jsx-runtime").JSX.Element;
9
+ export { Badge, badgeVariants };
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { type VariantProps } from 'class-variance-authority';
3
+ declare const buttonVariants: (props?: ({
4
+ variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
5
+ size?: "default" | "sm" | "lg" | "icon" | null | undefined;
6
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
+ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
8
+ asChild?: boolean;
9
+ }
10
+ declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
11
+ export { Button, buttonVariants };
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ declare const Card: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
3
+ declare const CardHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
4
+ declare const CardTitle: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLHeadingElement> & React.RefAttributes<HTMLParagraphElement>>;
5
+ declare const CardDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
6
+ declare const CardContent: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
7
+ declare const CardFooter: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
8
+ export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent };
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
3
+ declare const Dialog: React.FC<DialogPrimitive.DialogProps>;
4
+ declare const DialogTrigger: React.ForwardRefExoticComponent<DialogPrimitive.DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;
5
+ declare const DialogPortal: React.FC<DialogPrimitive.DialogPortalProps>;
6
+ declare const DialogClose: React.ForwardRefExoticComponent<DialogPrimitive.DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;
7
+ declare const DialogOverlay: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogOverlayProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
8
+ declare const DialogContent: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
9
+ declare const DialogHeader: {
10
+ ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
11
+ displayName: string;
12
+ };
13
+ declare const DialogFooter: {
14
+ ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
15
+ displayName: string;
16
+ };
17
+ declare const DialogTitle: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogTitleProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & React.RefAttributes<HTMLHeadingElement>>;
18
+ declare const DialogDescription: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogDescriptionProps & React.RefAttributes<HTMLParagraphElement>, "ref"> & React.RefAttributes<HTMLParagraphElement>>;
19
+ export { Dialog, DialogPortal, DialogOverlay, DialogClose, DialogTrigger, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, };
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
3
+ declare const DropdownMenu: React.FC<DropdownMenuPrimitive.DropdownMenuProps>;
4
+ declare const DropdownMenuTrigger: React.ForwardRefExoticComponent<DropdownMenuPrimitive.DropdownMenuTriggerProps & React.RefAttributes<HTMLButtonElement>>;
5
+ declare const DropdownMenuGroup: React.ForwardRefExoticComponent<DropdownMenuPrimitive.DropdownMenuGroupProps & React.RefAttributes<HTMLDivElement>>;
6
+ declare const DropdownMenuPortal: React.FC<DropdownMenuPrimitive.DropdownMenuPortalProps>;
7
+ declare const DropdownMenuSub: React.FC<DropdownMenuPrimitive.DropdownMenuSubProps>;
8
+ declare const DropdownMenuRadioGroup: React.ForwardRefExoticComponent<DropdownMenuPrimitive.DropdownMenuRadioGroupProps & React.RefAttributes<HTMLDivElement>>;
9
+ declare const DropdownMenuContent: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
10
+ declare const DropdownMenuItem: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
11
+ inset?: boolean;
12
+ } & React.RefAttributes<HTMLDivElement>>;
13
+ declare const DropdownMenuLabel: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuLabelProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
14
+ inset?: boolean;
15
+ } & React.RefAttributes<HTMLDivElement>>;
16
+ declare const DropdownMenuSeparator: React.ForwardRefExoticComponent<Omit<DropdownMenuPrimitive.DropdownMenuSeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
17
+ export { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuGroup, DropdownMenuPortal, DropdownMenuSub, DropdownMenuRadioGroup, };
@@ -0,0 +1,2 @@
1
+ declare const LoadingSpinner: () => import("react/jsx-runtime").JSX.Element;
2
+ export default LoadingSpinner;
@@ -0,0 +1,2 @@
1
+ declare function Skeleton({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
2
+ export { Skeleton };
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
3
+ declare const TooltipProvider: React.FC<TooltipPrimitive.TooltipProviderProps>;
4
+ declare const Tooltip: React.FC<TooltipPrimitive.TooltipProps>;
5
+ declare const TooltipTrigger: React.ForwardRefExoticComponent<TooltipPrimitive.TooltipTriggerProps & React.RefAttributes<HTMLButtonElement>>;
6
+ declare const TooltipContent: React.ForwardRefExoticComponent<Omit<TooltipPrimitive.TooltipContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
7
+ export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
@@ -0,0 +1,2 @@
1
+ import { type ClassValue } from "clsx";
2
+ export declare function cn(...inputs: ClassValue[]): string;
@@ -0,0 +1,57 @@
1
+ import type { AuthContextType, AuthProviderProps } from './types.js';
2
+ /**
3
+ * AuthProvider Component
4
+ *
5
+ * Main authentication provider that wraps your application with Logto authentication.
6
+ * Sets up authentication context, handles sign-in/sign-out flows, and manages auth state.
7
+ *
8
+ * @component
9
+ * @param {React.ReactNode} children - React components to wrap with authentication context
10
+ * @param {LogtoConfig} config - Logto configuration object containing endpoint, appId, and resources
11
+ * @param {string} [callbackUrl] - Default URL to redirect to after authentication (e.g., '/dashboard'). Can be overridden per sign-in call
12
+ * @param {Function} [customNavigate] - Custom navigation function for client-side routing (e.g., from React Router or Next.js). If not provided, uses window.location
13
+ * @param {boolean} [enablePopupSignIn=false] - Enable popup-based sign-in flow (opens sign-in in a new window). Defaults to redirect flow
14
+ * @param {(event: AuthTokenRefreshEvent) => void} [onTokenRefresh] - Called when an existing authenticated session receives a different access token
15
+ * @param {(event: AuthErrorEvent) => void} [onAuthError] - Called when auth loading hits a transient or definitive auth error
16
+ * @param {(event: AuthSignOutEvent) => void} [onSignOut] - Called immediately before the provider initiates local or global sign-out
17
+ *
18
+ * @example
19
+ * // Basic setup with Logto configuration
20
+ * <AuthProvider config={{ endpoint: 'https://tenant.logto.app', appId: 'app_id_here', resources: { api: 'urn:logto:resource:api' } }}>
21
+ * <App />
22
+ * </AuthProvider>
23
+ *
24
+ * @example
25
+ * // With custom React Router navigation
26
+ * import { useNavigate } from 'react-router-dom'
27
+ *
28
+ * function AuthProviderWrapper({ children }) {
29
+ * const navigate = useNavigate()
30
+ * return (
31
+ * <AuthProvider
32
+ * config={logtoConfig}
33
+ * callbackUrl="/dashboard"
34
+ * enablePopupSignIn={true}
35
+ * customNavigate={(url) => navigate(url)}
36
+ * >
37
+ * {children}
38
+ * </AuthProvider>
39
+ * )
40
+ * }
41
+ *
42
+ * @throws {Error} If required Logto configuration is missing or invalid (endpoint, appId)
43
+ */
44
+ export declare const AuthProvider: ({ children, config, callbackUrl, customNavigate, enablePopupSignIn, onTokenRefresh, onAuthError, onSignOut, }: AuthProviderProps) => import("react/jsx-runtime").JSX.Element;
45
+ /**
46
+ * useAuthContext Hook (Internal)
47
+ *
48
+ * Internal hook to access the authentication context. Not exported directly.
49
+ * Use the exported {@link useAuth} hook instead for the public API.
50
+ *
51
+ * @internal
52
+ * @returns {AuthContextType} Authentication context with user, loading state, and auth functions
53
+ * @throws {Error} If used outside of AuthProvider context
54
+ *
55
+ * @see {@link useAuth} for the public API to access auth context
56
+ */
57
+ export declare const useAuthContext: () => AuthContextType;