Files
Folo/apps/server/client/query/users.ts
T
7a6edb4575 feat: register or login with email and password (#2075)
* 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>
2024-12-16 19:13:46 +08:00

71 lines
2.1 KiB
TypeScript

import { apiClient } from "@client/lib/api-fetch"
import { getHydrateData } from "@client/lib/helper"
import { getProviders } from "@follow/shared/auth"
import { capitalizeFirstLetter, isBizId, parseUrl } from "@follow/utils/utils"
import { useQuery } from "@tanstack/react-query"
export const useUserSubscriptionsQuery = (userId: string | undefined) => {
return useQuery({
queryKey: ["subscriptions", "group", userId],
queryFn: async () => {
const res = await apiClient.subscriptions.$get({
query: { userId },
})
const groupFolder = {} as Record<string, typeof res.data>
for (const subscription of res.data || []) {
if (!subscription.category && "feeds" in subscription) {
const { siteUrl } = subscription.feeds
if (!siteUrl) continue
const parsed = parseUrl(siteUrl)
parsed.domain && (subscription.category = capitalizeFirstLetter(parsed.domain))
}
if (subscription.category) {
if (!groupFolder[subscription.category]) {
groupFolder[subscription.category] = []
}
groupFolder[subscription.category].push(subscription)
}
}
return groupFolder
},
enabled: !!userId,
})
}
export const fetchUser = async (handleOrId: string | undefined) => {
const handle = isBizId(handleOrId || "")
? handleOrId
: `${handleOrId}`.startsWith("@")
? `${handleOrId}`.slice(1)
: handleOrId
const res = await apiClient.profiles.$get({
query: {
handle,
id: isBizId(handle || "") ? handle : undefined,
},
})
return res.data
}
export const useUserQuery = (handleOrId: string | undefined) => {
return useQuery({
queryKey: ["profiles", handleOrId],
queryFn: () => fetchUser(handleOrId),
enabled: !!handleOrId,
initialData: getHydrateData(`profiles.$get,query:id=${handleOrId}`),
})
}
export interface AuthProvider {
name: string
id: string
color: string
icon: string
}
export const useAuthProviders = () => {
return useQuery({
queryKey: ["providers"],
queryFn: async () => (await getProviders()).data as Record<string, AuthProvider>,
})
}