Split user.ts into auth.ts and me.ts (#113)

Split user.ts into auth.ts and me.ts
This commit is contained in:
mrdrogdrog 2020-05-31 22:27:12 +02:00 committed by GitHub
parent 1fa8c8ac53
commit db5bec7000
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 53 additions and 51 deletions

40
src/api/auth.ts Normal file
View file

@ -0,0 +1,40 @@
import { expectResponseCode, getBackendUrl } from '../utils/apiUtils'
import { defaultFetchConfig } from './default'
export const doEmailLogin = async (email: string, password: string): Promise<void> => {
const response = await fetch(getBackendUrl() + '/auth/email', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
email: email,
password: password
})
})
expectResponseCode(response)
}
export const doLdapLogin = async (username: string, password: string): Promise<void> => {
const response = await fetch(getBackendUrl() + '/auth/ldap', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
username: username,
password: password
})
})
expectResponseCode(response)
}
export const doOpenIdLogin = async (openId: string): Promise<void> => {
const response = await fetch(getBackendUrl() + '/auth/openid', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
openId: openId
})
})
expectResponseCode(response)
}

View file

@ -15,44 +15,6 @@ export interface meResponse {
provider: LoginProvider
}
export const doEmailLogin = async (email: string, password: string): Promise<void> => {
const response = await fetch(getBackendUrl() + '/auth/email', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
email: email,
password: password
})
})
expectResponseCode(response)
}
export const doLdapLogin = async (username: string, password: string): Promise<void> => {
const response = await fetch(getBackendUrl() + '/auth/ldap', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
username: username,
password: password
})
})
expectResponseCode(response)
}
export const doOpenIdLogin = async (openId: string): Promise<void> => {
const response = await fetch(getBackendUrl() + '/auth/openid', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
openId: openId
})
})
expectResponseCode(response)
}
export const updateDisplayName = async (displayName: string): Promise<void> => {
const response = await fetch(getBackendUrl() + '/me', {
...defaultFetchConfig,