mirror of
https://github.com/Art051/immich.git
synced 2025-08-11 19:29:00 +00:00
Add web interface with admin functionality (#167)
This commit is contained in:
74
web/src/lib/auth-api.ts
Normal file
74
web/src/lib/auth-api.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
type AdminRegistrationResult = Promise<{
|
||||
error?: string
|
||||
success?: string
|
||||
user?: {
|
||||
email: string
|
||||
}
|
||||
}>
|
||||
|
||||
|
||||
|
||||
type LoginResult = Promise<{
|
||||
error?: string
|
||||
success?: string
|
||||
needUpdate?: boolean
|
||||
needSelectAdmin?: boolean
|
||||
user?: {
|
||||
accessToken: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
isAdmin: boolean
|
||||
id: string
|
||||
email: string
|
||||
}
|
||||
}>
|
||||
|
||||
type UpdateResult = Promise<{
|
||||
error?: string
|
||||
success?: string,
|
||||
user?: {
|
||||
accessToken: string
|
||||
firstName: string
|
||||
lastName: string
|
||||
isAdmin: boolean
|
||||
id: string
|
||||
email: string
|
||||
}
|
||||
}>
|
||||
|
||||
|
||||
export async function sendRegistrationForm(form: HTMLFormElement): AdminRegistrationResult {
|
||||
|
||||
const response = await fetch(form.action, {
|
||||
method: form.method,
|
||||
body: new FormData(form),
|
||||
headers: { accept: 'application/json' },
|
||||
})
|
||||
|
||||
return await response.json()
|
||||
|
||||
}
|
||||
|
||||
|
||||
export async function sendLoginForm(form: HTMLFormElement): LoginResult {
|
||||
|
||||
const response = await fetch(form.action, {
|
||||
method: form.method,
|
||||
body: new FormData(form),
|
||||
headers: { accept: 'application/json' },
|
||||
})
|
||||
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
export async function sendUpdateForm(form: HTMLFormElement): UpdateResult {
|
||||
|
||||
const response = await fetch(form.action, {
|
||||
method: form.method,
|
||||
body: new FormData(form),
|
||||
headers: { accept: 'application/json' },
|
||||
})
|
||||
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user