| 1 | import { createAuthPlugin } from "@better-auth-ui/core"; |
| 2 | import { |
| 3 | usernamePlugin as coreUsernamePlugin, |
| 4 | type UsernamePluginOptions, |
| 5 | } from "@better-auth-ui/core/plugins/username"; |
| 6 | |
| 7 | import { SignInUsername } from "@/components/auth/username/sign-in-username"; |
| 8 | import { UsernameField } from "@/components/auth/username/username-field"; |
| 9 | |
| 10 | export const usernamePlugin = createAuthPlugin( |
| 11 | coreUsernamePlugin.id, |
| 12 | (options: UsernamePluginOptions = {}) => { |
| 13 | const core = coreUsernamePlugin(options); |
| 14 | |
| 15 | return { |
| 16 | ...core, |
| 17 | additionalFields: core.additionalFields?.map((field) => |
| 18 | field.name === "username" |
| 19 | ? { |
| 20 | ...field, |
| 21 | render: UsernameField, |
| 22 | } |
| 23 | : field, |
| 24 | ), |
| 25 | views: { |
| 26 | auth: { signIn: SignInUsername }, |
| 27 | }, |
| 28 | }; |
| 29 | }, |
| 30 | ); |