@better-auth-ui/core 1.6.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.
- package/dist/base-paths.d.ts +21 -0
- package/dist/base-paths.js +5 -0
- package/dist/config/appearance-config.d.ts +23 -0
- package/dist/config/appearance-config.js +1 -0
- package/dist/config/auth-config.d.ts +87 -0
- package/dist/config/auth-config.js +35 -0
- package/dist/config/avatar-config.d.ts +35 -0
- package/dist/config/avatar-config.js +1 -0
- package/dist/config/delete-user-config.d.ts +14 -0
- package/dist/config/delete-user-config.js +1 -0
- package/dist/config/email-and-password-config.d.ts +37 -0
- package/dist/config/email-and-password-config.js +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.js +5 -0
- package/dist/config/settings-config.d.ts +17 -0
- package/dist/config/settings-config.js +1 -0
- package/dist/config/toast-config.d.ts +58 -0
- package/dist/config/toast-config.js +16 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/lib/auth-callback-options.d.ts +8 -0
- package/dist/lib/auth-callback-options.js +1 -0
- package/dist/lib/auth-config.d.ts +198 -0
- package/dist/lib/auth-config.js +36 -0
- package/dist/lib/auth-error.d.ts +9 -0
- package/dist/lib/auth-error.js +1 -0
- package/dist/lib/auth-hook-options.d.ts +8 -0
- package/dist/lib/auth-hook-options.js +1 -0
- package/dist/lib/auth-toast.d.ts +24 -0
- package/dist/lib/auth-toast.js +10 -0
- package/dist/lib/base-paths.d.ts +21 -0
- package/dist/lib/base-paths.js +5 -0
- package/dist/lib/config/appearance-config.d.ts +23 -0
- package/dist/lib/config/appearance-config.js +1 -0
- package/dist/lib/config/auth-config.d.ts +70 -0
- package/dist/lib/config/auth-config.js +36 -0
- package/dist/lib/config/avatar-config.d.ts +35 -0
- package/dist/lib/config/avatar-config.js +1 -0
- package/dist/lib/config/email-and-password-config.d.ts +37 -0
- package/dist/lib/config/email-and-password-config.js +1 -0
- package/dist/lib/config/index.d.ts +6 -0
- package/dist/lib/config/index.js +6 -0
- package/dist/lib/config/settings-config.d.ts +22 -0
- package/dist/lib/config/settings-config.js +1 -0
- package/dist/lib/config/toast-config.d.ts +24 -0
- package/dist/lib/config/toast-config.js +10 -0
- package/dist/lib/localization.d.ts +175 -0
- package/dist/lib/localization.js +172 -0
- package/dist/lib/provider-names.d.ts +12 -0
- package/dist/lib/provider-names.js +50 -0
- package/dist/lib/toast-config.d.ts +24 -0
- package/dist/lib/toast-config.js +10 -0
- package/dist/lib/utils.d.ts +32 -0
- package/dist/lib/utils.js +116 -0
- package/dist/lib/view-paths.d.ts +68 -0
- package/dist/lib/view-paths.js +14 -0
- package/dist/localization/index.d.ts +35 -0
- package/dist/localization/index.js +34 -0
- package/dist/localization/localization.d.ts +35 -0
- package/dist/localization/localization.js +34 -0
- package/dist/localization.d.ts +159 -0
- package/dist/localization.js +156 -0
- package/dist/provider-names.d.ts +12 -0
- package/dist/provider-names.js +50 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +7 -0
- package/dist/src/lib/auth-config.d.ts +148 -0
- package/dist/src/lib/auth-config.js +28 -0
- package/dist/src/lib/auth-toast.d.ts +24 -0
- package/dist/src/lib/auth-toast.js +10 -0
- package/dist/src/lib/base-paths.d.ts +9 -0
- package/dist/src/lib/base-paths.js +9 -0
- package/dist/src/lib/localization.d.ts +145 -0
- package/dist/src/lib/localization.js +142 -0
- package/dist/src/lib/provider-names.d.ts +12 -0
- package/dist/src/lib/provider-names.js +49 -0
- package/dist/src/lib/utils.d.ts +1 -0
- package/dist/src/lib/utils.js +30 -0
- package/dist/src/lib/view-paths.d.ts +30 -0
- package/dist/src/lib/view-paths.js +17 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +80 -0
- package/dist/view-paths.d.ts +30 -0
- package/dist/view-paths.js +17 -0
- package/package.json +32 -0
- package/src/config/appearance-config.ts +24 -0
- package/src/config/auth-config.ts +117 -0
- package/src/config/avatar-config.ts +39 -0
- package/src/config/delete-user-config.ts +14 -0
- package/src/config/email-and-password-config.ts +37 -0
- package/src/config/index.ts +5 -0
- package/src/index.ts +6 -0
- package/src/lib/base-paths.ts +26 -0
- package/src/lib/localization.ts +259 -0
- package/src/lib/provider-names.ts +55 -0
- package/src/lib/utils.ts +151 -0
- package/src/lib/view-paths.ts +86 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base path configuration for authentication, settings, and organization routes.
|
|
3
|
+
*/
|
|
4
|
+
export type BasePaths = {
|
|
5
|
+
/**
|
|
6
|
+
* Base path for authentication routes
|
|
7
|
+
* @default "/auth"
|
|
8
|
+
*/
|
|
9
|
+
auth: string;
|
|
10
|
+
/**
|
|
11
|
+
* Base path for settings routes
|
|
12
|
+
* @default "/settings"
|
|
13
|
+
*/
|
|
14
|
+
settings: string;
|
|
15
|
+
/**
|
|
16
|
+
* Base path for organization management routes
|
|
17
|
+
* @default "/organization"
|
|
18
|
+
*/
|
|
19
|
+
organization: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const basePaths: BasePaths;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Available theme options for the application.
|
|
3
|
+
*/
|
|
4
|
+
export type Theme = "system" | "light" | "dark";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for appearance/theme settings.
|
|
7
|
+
*/
|
|
8
|
+
export type AppearanceConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* Function to set the application theme
|
|
11
|
+
* @param theme - The theme value to set
|
|
12
|
+
*/
|
|
13
|
+
setTheme?: (theme: string) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Current theme value
|
|
16
|
+
*/
|
|
17
|
+
theme?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Available theme options to display in the theme switcher
|
|
20
|
+
* @default ["system", "light", "dark"]
|
|
21
|
+
*/
|
|
22
|
+
themes: Theme[];
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { SocialProvider } from "better-auth/social-providers";
|
|
2
|
+
import { type BasePaths } from "../lib/base-paths";
|
|
3
|
+
import { type Localization } from "../lib/localization";
|
|
4
|
+
import { type ViewPaths } from "../lib/view-paths";
|
|
5
|
+
import type { AppearanceConfig } from "./appearance-config";
|
|
6
|
+
import type { AvatarConfig } from "./avatar-config";
|
|
7
|
+
import type { DeleteUserConfig } from "./delete-user-config";
|
|
8
|
+
import type { EmailAndPasswordConfig } from "./email-and-password-config";
|
|
9
|
+
/**
|
|
10
|
+
* Core authentication configuration interface.
|
|
11
|
+
*
|
|
12
|
+
* Defines the base structure for authentication settings including paths,
|
|
13
|
+
* providers, navigation functions, and feature flags.
|
|
14
|
+
*/
|
|
15
|
+
export interface AuthConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Appearance/theme configuration
|
|
18
|
+
* @remarks `AppearanceConfig`
|
|
19
|
+
* @default { themes: ["system", "light", "dark"] }
|
|
20
|
+
*/
|
|
21
|
+
appearance: AppearanceConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Avatar upload, optimization, and deletion configuration.
|
|
24
|
+
* @remarks `AvatarConfig`
|
|
25
|
+
* @default { enabled: true, resize: resizeAvatar, size: 256, extension: "png" }
|
|
26
|
+
*/
|
|
27
|
+
avatar: AvatarConfig;
|
|
28
|
+
/**
|
|
29
|
+
* Base paths for different application sections
|
|
30
|
+
* @remarks `BasePaths`
|
|
31
|
+
*/
|
|
32
|
+
basePaths: BasePaths;
|
|
33
|
+
/**
|
|
34
|
+
* Base URL for API endpoints (optional)
|
|
35
|
+
* @default ""
|
|
36
|
+
*/
|
|
37
|
+
baseURL: string;
|
|
38
|
+
/**
|
|
39
|
+
* Allow users to delete their account
|
|
40
|
+
* @remarks `DeleteUserConfig`
|
|
41
|
+
*/
|
|
42
|
+
deleteUser?: DeleteUserConfig;
|
|
43
|
+
/**
|
|
44
|
+
* Email and password authentication configuration
|
|
45
|
+
* @remarks `EmailAndPasswordConfig`
|
|
46
|
+
*/
|
|
47
|
+
emailAndPassword: EmailAndPasswordConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Localization strings for UI components
|
|
50
|
+
* @remarks `Localization`
|
|
51
|
+
*/
|
|
52
|
+
localization: Localization;
|
|
53
|
+
/** Whether magic link (passwordless) authentication is enabled */
|
|
54
|
+
magicLink?: boolean;
|
|
55
|
+
/** Whether multi-session support is enabled */
|
|
56
|
+
multiSession?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Default redirect path after successful authentication
|
|
59
|
+
* @default "/"
|
|
60
|
+
*/
|
|
61
|
+
redirectTo: string;
|
|
62
|
+
/**
|
|
63
|
+
* List of enabled social authentication providers
|
|
64
|
+
* @remarks `SocialProvider[]`
|
|
65
|
+
*/
|
|
66
|
+
socialProviders?: SocialProvider[];
|
|
67
|
+
/**
|
|
68
|
+
* View path mappings for different authentication views
|
|
69
|
+
* @remarks `ViewPaths`
|
|
70
|
+
*/
|
|
71
|
+
viewPaths: ViewPaths;
|
|
72
|
+
/**
|
|
73
|
+
* Function to navigate to a new path
|
|
74
|
+
* @param options - Navigation options with href and optional replace flag
|
|
75
|
+
* @default window.location.href = href (or window.location.replace if replace: true)
|
|
76
|
+
* @example
|
|
77
|
+
* // TanStack Router
|
|
78
|
+
* navigate={navigate}
|
|
79
|
+
* // Next.js
|
|
80
|
+
* navigate={({href, replace}) => replace ? router.replace(href) : router.push(href)}
|
|
81
|
+
*/
|
|
82
|
+
navigate: (options: {
|
|
83
|
+
to: string;
|
|
84
|
+
replace?: boolean;
|
|
85
|
+
}) => void;
|
|
86
|
+
}
|
|
87
|
+
export declare const defaultAuthConfig: AuthConfig;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { basePaths } from "../lib/base-paths";
|
|
2
|
+
import { localization } from "../lib/localization";
|
|
3
|
+
import { resizeAvatar } from "../lib/utils";
|
|
4
|
+
import { viewPaths } from "../lib/view-paths";
|
|
5
|
+
export const defaultAuthConfig = {
|
|
6
|
+
appearance: {
|
|
7
|
+
themes: ["system", "light", "dark"]
|
|
8
|
+
},
|
|
9
|
+
avatar: {
|
|
10
|
+
enabled: true,
|
|
11
|
+
resize: resizeAvatar,
|
|
12
|
+
size: 256,
|
|
13
|
+
extension: "png"
|
|
14
|
+
},
|
|
15
|
+
basePaths,
|
|
16
|
+
baseURL: "",
|
|
17
|
+
emailAndPassword: {
|
|
18
|
+
enabled: true,
|
|
19
|
+
forgotPassword: true,
|
|
20
|
+
rememberMe: false,
|
|
21
|
+
minPasswordLength: 8,
|
|
22
|
+
maxPasswordLength: 128
|
|
23
|
+
},
|
|
24
|
+
redirectTo: "/",
|
|
25
|
+
viewPaths,
|
|
26
|
+
localization,
|
|
27
|
+
navigate: ({ to, replace }) => {
|
|
28
|
+
if (replace) {
|
|
29
|
+
window.location.replace(to);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
window.location.href = to;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for avatar handling.
|
|
3
|
+
*/
|
|
4
|
+
export type AvatarConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* Delete the current avatar (e.g. remove from storage).
|
|
7
|
+
* Gets called after the user's avatar is updated to null.
|
|
8
|
+
*/
|
|
9
|
+
delete?: (url: string) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Whether avatar changing is enabled.
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Output image format.
|
|
17
|
+
* @default "png"
|
|
18
|
+
*/
|
|
19
|
+
extension: "png" | "jpg" | "webp" | "inherit";
|
|
20
|
+
/**
|
|
21
|
+
* Resize an image file before upload. Overrides the default resize behavior.
|
|
22
|
+
* @default Resizes to `size` pixels, square-cropped, output as `extension`.
|
|
23
|
+
*/
|
|
24
|
+
resize: (file: File, size?: number, extension?: "png" | "jpg" | "webp" | "inherit") => Promise<File>;
|
|
25
|
+
/**
|
|
26
|
+
* Max dimension in pixels for the optimized avatar.
|
|
27
|
+
* @default 256
|
|
28
|
+
*/
|
|
29
|
+
size: number;
|
|
30
|
+
/**
|
|
31
|
+
* Upload a file and return the URL where it was stored.
|
|
32
|
+
* When undefined, the image is base64-encoded and saved directly to `user.image`.
|
|
33
|
+
*/
|
|
34
|
+
upload?: (file: File) => Promise<string>;
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for account deletion in the UI (mirrors server `user.deleteUser` flags).
|
|
3
|
+
*/
|
|
4
|
+
export interface DeleteUserConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the delete user feature is enabled.
|
|
7
|
+
*/
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* When `true`, matches server `sendDeleteAccountVerification`: deletion starts by sending a
|
|
11
|
+
* verification email instead of deleting immediately in this request.
|
|
12
|
+
*/
|
|
13
|
+
sendDeleteAccountVerification?: boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for email and password authentication.
|
|
3
|
+
*/
|
|
4
|
+
export type EmailAndPasswordConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* Whether email/password authentication is enabled
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to show a confirm password field on sign-up forms
|
|
12
|
+
*/
|
|
13
|
+
confirmPassword?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether users can reset forgotten passwords
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
forgotPassword: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum password length
|
|
21
|
+
* @default 128
|
|
22
|
+
*/
|
|
23
|
+
maxPasswordLength: number;
|
|
24
|
+
/**
|
|
25
|
+
* Minimum password length
|
|
26
|
+
* @default 8
|
|
27
|
+
*/
|
|
28
|
+
minPasswordLength: number;
|
|
29
|
+
/**
|
|
30
|
+
* Maximum password length
|
|
31
|
+
* @default 128
|
|
32
|
+
*/
|
|
33
|
+
/** Whether to show a "Remember me" checkbox on sign-in forms */
|
|
34
|
+
rememberMe?: boolean;
|
|
35
|
+
/** Whether email verification is required before account activation */
|
|
36
|
+
requireEmailVerification?: boolean;
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AppearanceConfig } from "./appearance-config";
|
|
2
|
+
import type { AvatarConfig } from "./avatar-config";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for user settings.
|
|
5
|
+
*/
|
|
6
|
+
export type SettingsConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* Appearance/theme configuration
|
|
9
|
+
* @default { themes: ["system", "light", "dark"] }
|
|
10
|
+
*/
|
|
11
|
+
appearance: AppearanceConfig;
|
|
12
|
+
/**
|
|
13
|
+
* Avatar upload, optimization, and deletion configuration.
|
|
14
|
+
* @default { enabled: true, optimize: optimizeAvatar, size: 256 }
|
|
15
|
+
*/
|
|
16
|
+
avatar: AvatarConfig;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function signature for rendering a toast notification.
|
|
3
|
+
*
|
|
4
|
+
* @param message - The message to display in the toast.
|
|
5
|
+
* @param options - Optional configuration for the toast.
|
|
6
|
+
* @param options.action - Action button displayed within the toast.
|
|
7
|
+
* @param options.action.label - Label text for the action button.
|
|
8
|
+
* @param options.action.onClick - Callback invoked when the action button is clicked.
|
|
9
|
+
* @param options.actionProps - Alternative action props (used by some toast libraries).
|
|
10
|
+
* @param options.actionProps.children - Label text for the action button.
|
|
11
|
+
* @param options.actionProps.onClick - Callback invoked when the action button is clicked.
|
|
12
|
+
* @returns A toast identifier (type varies by toast library), or void.
|
|
13
|
+
*/
|
|
14
|
+
export type RenderToast = (message?: string, options?: {
|
|
15
|
+
action?: {
|
|
16
|
+
label: string;
|
|
17
|
+
onClick: () => Promise<void> | void;
|
|
18
|
+
};
|
|
19
|
+
actionProps?: {
|
|
20
|
+
children: string;
|
|
21
|
+
onClick: () => Promise<void> | void;
|
|
22
|
+
};
|
|
23
|
+
}) => string | number | unknown;
|
|
24
|
+
/**
|
|
25
|
+
* Function signature for dismissing a toast notification by its ID.
|
|
26
|
+
*
|
|
27
|
+
* @param id - The identifier of the toast to dismiss (returned by {@link RenderToast}).
|
|
28
|
+
* @returns A toast identifier, or void.
|
|
29
|
+
*/
|
|
30
|
+
export type DismissToast = (id?: number | string | unknown | any) => string | number | unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Fallback toast implementation using native browser dialogs.
|
|
33
|
+
*
|
|
34
|
+
* Uses `confirm()` for toasts with an action (invokes the action on confirm)
|
|
35
|
+
* and `alert()` for plain messages.
|
|
36
|
+
*/
|
|
37
|
+
export declare const defaultToast: RenderToast;
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for toast notifications used throughout the UI.
|
|
40
|
+
*
|
|
41
|
+
* Provide your own toast library functions (e.g. sonner, react-hot-toast)
|
|
42
|
+
* to customize how notifications are displayed.
|
|
43
|
+
*/
|
|
44
|
+
export type ToastConfig = {
|
|
45
|
+
/** Display an error toast notification. */
|
|
46
|
+
error: RenderToast;
|
|
47
|
+
/** Display a danger toast notification (e.g. destructive actions). */
|
|
48
|
+
danger?: RenderToast;
|
|
49
|
+
/** Display a success toast notification. */
|
|
50
|
+
success: RenderToast;
|
|
51
|
+
/** Display an informational toast notification. */
|
|
52
|
+
info: RenderToast;
|
|
53
|
+
/**
|
|
54
|
+
* Dismiss a toast notification by its ID.
|
|
55
|
+
* When provided, allows programmatic dismissal of active toasts.
|
|
56
|
+
*/
|
|
57
|
+
dismiss?: DismissToast;
|
|
58
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fallback toast implementation using native browser dialogs.
|
|
3
|
+
*
|
|
4
|
+
* Uses `confirm()` for toasts with an action (invokes the action on confirm)
|
|
5
|
+
* and `alert()` for plain messages.
|
|
6
|
+
*/
|
|
7
|
+
export const defaultToast = (message, options) => {
|
|
8
|
+
if (options?.action) {
|
|
9
|
+
if (confirm(message)) {
|
|
10
|
+
options.action.onClick();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
alert(message);
|
|
15
|
+
}
|
|
16
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type { SocialProvider } from "better-auth/social-providers";
|
|
2
|
+
import { type Toast } from "./auth-toast";
|
|
3
|
+
import { type Localization } from "./localization";
|
|
4
|
+
import { type ViewPaths } from "./view-paths";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for email and password authentication.
|
|
7
|
+
*/
|
|
8
|
+
export type EmailAndPasswordConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* Whether email/password authentication is enabled
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to show a confirm password field on sign-up forms
|
|
16
|
+
*/
|
|
17
|
+
confirmPassword?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether users can reset forgotten passwords
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
forgotPassword: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Maximum password length
|
|
25
|
+
* @default 128
|
|
26
|
+
*/
|
|
27
|
+
maxPasswordLength?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Minimum password length
|
|
30
|
+
* @default 8
|
|
31
|
+
*/
|
|
32
|
+
minPasswordLength?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum password length
|
|
35
|
+
* @default 128
|
|
36
|
+
*/
|
|
37
|
+
/** Whether to show a "Remember me" checkbox on sign-in forms */
|
|
38
|
+
rememberMe?: boolean;
|
|
39
|
+
/** Whether email verification is required before account activation */
|
|
40
|
+
requireEmailVerification?: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Configuration options for avatar handling.
|
|
44
|
+
*/
|
|
45
|
+
export type AvatarConfig = {
|
|
46
|
+
/**
|
|
47
|
+
* Delete the current avatar (e.g. remove from storage).
|
|
48
|
+
* When undefined, avatar deletion is disabled.
|
|
49
|
+
*/
|
|
50
|
+
delete?: (url: string) => Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether avatar changing is enabled.
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
enabled?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Output image format.
|
|
58
|
+
* @default "png"
|
|
59
|
+
*/
|
|
60
|
+
extension?: "png" | "jpg" | "webp" | "inherit";
|
|
61
|
+
/**
|
|
62
|
+
* Resize an image file before upload.
|
|
63
|
+
* @default Resizes to max size, square-cropped, output as configured extension.
|
|
64
|
+
*/
|
|
65
|
+
resize?: (file: File, size?: number, extension?: "png" | "jpg" | "webp" | "inherit") => Promise<File>;
|
|
66
|
+
/**
|
|
67
|
+
* Max dimension in pixels for the optimized avatar.
|
|
68
|
+
* @default 256
|
|
69
|
+
*/
|
|
70
|
+
size?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Upload a file and return the URL where it was stored.
|
|
73
|
+
* When undefined, the image is base64-encoded and saved directly to `user.image`.
|
|
74
|
+
*/
|
|
75
|
+
upload?: (file: File) => Promise<string>;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Available theme options for the application.
|
|
79
|
+
*/
|
|
80
|
+
export type Theme = "system" | "light" | "dark";
|
|
81
|
+
/**
|
|
82
|
+
* Configuration options for appearance/theme settings.
|
|
83
|
+
*/
|
|
84
|
+
export type AppearanceConfig = {
|
|
85
|
+
/**
|
|
86
|
+
* Function to set the application theme
|
|
87
|
+
* @param theme - The theme value to set
|
|
88
|
+
*/
|
|
89
|
+
setTheme?: (theme: string) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Current theme value
|
|
92
|
+
*/
|
|
93
|
+
theme?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Available theme options to display in the theme switcher
|
|
96
|
+
* @default ["system", "light", "dark"]
|
|
97
|
+
*/
|
|
98
|
+
themes?: Theme[];
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Configuration options for user settings.
|
|
102
|
+
*/
|
|
103
|
+
export type SettingsConfig = {
|
|
104
|
+
/**
|
|
105
|
+
* Appearance/theme configuration
|
|
106
|
+
* @default { themes: ["system", "light", "dark"] }
|
|
107
|
+
*/
|
|
108
|
+
appearance: AppearanceConfig;
|
|
109
|
+
/**
|
|
110
|
+
* Avatar upload, optimization, and deletion configuration.
|
|
111
|
+
* @default { enabled: true, optimize: optimizeAvatar, size: 256 }
|
|
112
|
+
*/
|
|
113
|
+
avatar: AvatarConfig;
|
|
114
|
+
/**
|
|
115
|
+
* Whether the settings section is enabled
|
|
116
|
+
* @default true
|
|
117
|
+
*/
|
|
118
|
+
enabled?: boolean;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Core authentication configuration interface.
|
|
122
|
+
*
|
|
123
|
+
* Defines the base structure for authentication settings including paths,
|
|
124
|
+
* providers, navigation functions, and feature flags.
|
|
125
|
+
*/
|
|
126
|
+
export interface AuthConfig {
|
|
127
|
+
/** Base paths for different application sections */
|
|
128
|
+
basePaths: {
|
|
129
|
+
/**
|
|
130
|
+
* Base path for authentication routes
|
|
131
|
+
* @default "/auth"
|
|
132
|
+
*/
|
|
133
|
+
auth: string;
|
|
134
|
+
/**
|
|
135
|
+
* Base path for settings routes
|
|
136
|
+
* @default "/settings"
|
|
137
|
+
*/
|
|
138
|
+
settings: string;
|
|
139
|
+
/**
|
|
140
|
+
* Base path for organization management routes
|
|
141
|
+
* @default "/organization"
|
|
142
|
+
*/
|
|
143
|
+
organization: string;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Base URL for API endpoints (optional)
|
|
147
|
+
* @default ""
|
|
148
|
+
*/
|
|
149
|
+
baseURL: string;
|
|
150
|
+
/**
|
|
151
|
+
* Email and password authentication configuration
|
|
152
|
+
* @default { enabled: true, forgotPassword: true, minPasswordLength: 8, maxPasswordLength: 128 }
|
|
153
|
+
*/
|
|
154
|
+
emailAndPassword: EmailAndPasswordConfig;
|
|
155
|
+
/** Localization strings for UI components. */
|
|
156
|
+
localization: Localization;
|
|
157
|
+
/** Whether magic link (passwordless) authentication is enabled */
|
|
158
|
+
magicLink?: boolean;
|
|
159
|
+
/** Whether multi-session support is enabled */
|
|
160
|
+
multiSession?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Default redirect path after successful authentication
|
|
163
|
+
* @default "/"
|
|
164
|
+
*/
|
|
165
|
+
redirectTo: string;
|
|
166
|
+
/**
|
|
167
|
+
* Settings section configuration
|
|
168
|
+
* @default { enabled: true }
|
|
169
|
+
*/
|
|
170
|
+
settings: SettingsConfig;
|
|
171
|
+
/**
|
|
172
|
+
* List of enabled social authentication providers
|
|
173
|
+
* @remarks `SocialProvider[]`
|
|
174
|
+
*/
|
|
175
|
+
socialProviders?: SocialProvider[];
|
|
176
|
+
/** View path mappings for different authentication views */
|
|
177
|
+
viewPaths: ViewPaths;
|
|
178
|
+
/**
|
|
179
|
+
* Toast notification configuration for user feedback.
|
|
180
|
+
* @remarks `Toast`
|
|
181
|
+
*/
|
|
182
|
+
toast: Toast;
|
|
183
|
+
/**
|
|
184
|
+
* Function to navigate to a new path
|
|
185
|
+
* @param options - Navigation options with href and optional replace flag
|
|
186
|
+
* @default window.location.href = href (or window.location.replace if replace: true)
|
|
187
|
+
* @example
|
|
188
|
+
* // TanStack Router
|
|
189
|
+
* navigate={navigate}
|
|
190
|
+
* // Next.js
|
|
191
|
+
* navigate={({href, replace}) => replace ? router.replace(href) : router.push(href)}
|
|
192
|
+
*/
|
|
193
|
+
navigate: (options: {
|
|
194
|
+
to: string;
|
|
195
|
+
replace?: boolean;
|
|
196
|
+
}) => void;
|
|
197
|
+
}
|
|
198
|
+
export declare const defaultConfig: AuthConfig;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { defaultToast } from "./auth-toast";
|
|
2
|
+
import { basePaths } from "./base-paths";
|
|
3
|
+
import { localization } from "./localization";
|
|
4
|
+
import { resizeAvatar } from "./utils";
|
|
5
|
+
import { viewPaths } from "./view-paths";
|
|
6
|
+
export const defaultConfig = {
|
|
7
|
+
basePaths,
|
|
8
|
+
baseURL: "",
|
|
9
|
+
emailAndPassword: {
|
|
10
|
+
enabled: true,
|
|
11
|
+
forgotPassword: true,
|
|
12
|
+
rememberMe: false,
|
|
13
|
+
minPasswordLength: 8,
|
|
14
|
+
maxPasswordLength: 128
|
|
15
|
+
},
|
|
16
|
+
redirectTo: "/",
|
|
17
|
+
settings: {
|
|
18
|
+
appearance: {
|
|
19
|
+
themes: ["system", "light", "dark"]
|
|
20
|
+
},
|
|
21
|
+
avatar: {
|
|
22
|
+
enabled: true,
|
|
23
|
+
resize: resizeAvatar,
|
|
24
|
+
size: 256
|
|
25
|
+
},
|
|
26
|
+
enabled: true
|
|
27
|
+
},
|
|
28
|
+
viewPaths,
|
|
29
|
+
localization,
|
|
30
|
+
navigate: () => { },
|
|
31
|
+
toast: {
|
|
32
|
+
error: defaultToast,
|
|
33
|
+
success: defaultToast,
|
|
34
|
+
info: defaultToast
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|