* feat: login with password * chore: auto-fix linting and formatting issues * feat: show email * refactor: login form * chore: update * fix: show login error * chore: update * credential provider * feat: confirm password * chore: update * revokeOtherSessions when update password * changelog * typecheck * chore: update * chore: update hono * feat: forget password * chore: update * feat: reset password page * feat: register form * chore: update * chore: update * chore: update * chore: update * fix: email login handler * fix: navigate to login after register * chore: remove forget password button for now * chore: update * feat: forget password page * chore: update hono * fix: forget-password link * feat: login email text * refactor: enhance login and forget password functionality - Updated the forget password page to include a back navigation button using MotionButtonBase. - Refactored the login component to utilize the new Login module, simplifying the structure. - Adjusted translations for consistency in the login text across English and German locales. - Improved the useAuthProviders hook to return a more structured AuthProvider interface. Signed-off-by: Innei <tukon479@gmail.com> * feat: add form validation and UI enhancements for login-related pages - Introduced form validation state management in forget-password, register, and reset-password components. - Updated button states to be disabled when forms are invalid, improving user experience. - Enhanced UI elements with consistent styling and layout adjustments, including the addition of MotionButtonBase for navigation. - Improved accessibility and responsiveness of card components. Signed-off-by: Innei <tukon479@gmail.com> * feat: enhance login component with dynamic provider buttons - Added MotionButtonBase for improved button animations and interactions. - Refactored the rendering logic to conditionally display login options based on the presence of credential providers. - Introduced a new icon mapping for providers to enhance visual representation. - Improved layout and styling for better user experience during login. Signed-off-by: Innei <tukon479@gmail.com> * feat: add GitHub provider icon and adjust button margin in login component - Introduced a GitHub icon to the provider icon map for enhanced visual representation. - Adjusted the margin of the submit button to improve layout consistency. Signed-off-by: Innei <tukon479@gmail.com> * chore: update --------- Signed-off-by: Innei <tukon479@gmail.com> Co-authored-by: hyoban <hyoban@users.noreply.github.com> Co-authored-by: DIYgod <i@diygod.me> Co-authored-by: Innei <tukon479@gmail.com> Signed-off-by: Innei <tukon479@gmail.com>
76 lines
1.7 KiB
TypeScript
76 lines
1.7 KiB
TypeScript
import { env } from "@follow/shared/env"
|
|
import type { authPlugins } from "@follow/shared/hono"
|
|
import type { BetterAuthClientPlugin } from "better-auth/client"
|
|
import { createAuthClient } from "better-auth/react"
|
|
|
|
import { IN_ELECTRON, WEB_URL } from "./constants"
|
|
|
|
const serverPlugins = [
|
|
{
|
|
id: "getProviders",
|
|
$InferServerPlugin: {} as (typeof authPlugins)[0],
|
|
},
|
|
{
|
|
id: "createSession",
|
|
$InferServerPlugin: {} as (typeof authPlugins)[1],
|
|
},
|
|
inferAdditionalFields({
|
|
user: {
|
|
handle: {
|
|
type: "string",
|
|
required: false,
|
|
},
|
|
},
|
|
}),
|
|
] satisfies BetterAuthClientPlugin[]
|
|
|
|
const authClient = createAuthClient({
|
|
baseURL: `${env.VITE_API_URL}/better-auth`,
|
|
plugins: serverPlugins,
|
|
})
|
|
|
|
// @keep-sorted
|
|
export const {
|
|
changePassword,
|
|
createSession,
|
|
forgetPassword,
|
|
getProviders,
|
|
getSession,
|
|
linkSocial,
|
|
listAccounts,
|
|
resetPassword,
|
|
signIn,
|
|
signOut,
|
|
signUp,
|
|
updateUser,
|
|
} = authClient
|
|
|
|
export const LOGIN_CALLBACK_URL = `${WEB_URL}/login`
|
|
export type LoginRuntime = "browser" | "app"
|
|
export const loginHandler = async (
|
|
provider: string,
|
|
runtime?: LoginRuntime,
|
|
args?: {
|
|
email?: string
|
|
password?: string
|
|
},
|
|
) => {
|
|
const { email, password } = args ?? {}
|
|
if (IN_ELECTRON) {
|
|
window.open(`${WEB_URL}/login?provider=${provider}`)
|
|
} else {
|
|
if (provider === "credential") {
|
|
if (!email || !password) {
|
|
window.location.href = "/login"
|
|
return
|
|
}
|
|
return signIn.email({ email, password })
|
|
}
|
|
|
|
signIn.social({
|
|
provider: provider as "google" | "github" | "apple",
|
|
callbackURL: runtime === "app" ? LOGIN_CALLBACK_URL : undefined,
|
|
})
|
|
}
|
|
}
|