Files
qwqcode dcde53f8ad refactor(ui/auth): ensure compatibility with new client types (#1009)
- Bump to new Artalk client export types
- Add `AuthContext` type definition for improved clarity
- Replace `ContextApi` with `AuthContext` for reducing the scope of variables
- Bump version to 0.0.2 for release

(The prerequisite PR is #1007)
2024-10-18 17:09:15 +08:00

28 lines
715 B
TypeScript

import type { Api } from 'artalk'
export interface LoginMethod {
name: string
label: string
icon: string
link?: string
onClick?: () => void
}
export const fetchMethods = async (api: Api) => {
const { data } = await api.conf.getSocialLoginProviders()
return data.providers
.map<LoginMethod>(({ name, label, icon, path }) => {
return { name, label, icon, link: path }
})
.sort((a, b) => {
// email always on top
if (a.name === 'email') return -1
if (b.name === 'email') return 1
// skip always on bottom
if (a.name === 'skip') return 1
if (b.name === 'skip') return -1
// others by label
return a.label.localeCompare(b.label)
})
}