mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 00:54:43 -04:00
Split user.ts into auth.ts and me.ts (#113)
Split user.ts into auth.ts and me.ts
This commit is contained in:
parent
1fa8c8ac53
commit
db5bec7000
9 changed files with 53 additions and 51 deletions
40
src/api/auth.ts
Normal file
40
src/api/auth.ts
Normal 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)
|
||||||
|
}
|
|
@ -15,44 +15,6 @@ export interface meResponse {
|
||||||
provider: LoginProvider
|
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> => {
|
export const updateDisplayName = async (displayName: string): Promise<void> => {
|
||||||
const response = await fetch(getBackendUrl() + '/me', {
|
const response = await fetch(getBackendUrl() + '/me', {
|
||||||
...defaultFetchConfig,
|
...defaultFetchConfig,
|
|
@ -1,7 +1,7 @@
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
|
||||||
import { Alert, Button, Card, Form } from 'react-bootstrap'
|
|
||||||
import React, { FormEvent, useState } from 'react'
|
import React, { FormEvent, useState } from 'react'
|
||||||
import { doEmailLogin } from '../../../../../api/user'
|
import { Alert, Button, Card, Form } from 'react-bootstrap'
|
||||||
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
|
import { doEmailLogin } from '../../../../../api/auth'
|
||||||
import { getAndSetUser } from '../../../../../utils/apiUtils'
|
import { getAndSetUser } from '../../../../../utils/apiUtils'
|
||||||
|
|
||||||
export const ViaEMail: React.FC = () => {
|
export const ViaEMail: React.FC = () => {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import React, { FormEvent, useState } from 'react'
|
import React, { FormEvent, useState } from 'react'
|
||||||
|
import { Alert, Button, Card, Form } from 'react-bootstrap'
|
||||||
|
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { Alert, Button, Card, Form } from 'react-bootstrap'
|
|
||||||
import { doLdapLogin } from '../../../../../api/user'
|
|
||||||
import { getAndSetUser } from '../../../../../utils/apiUtils'
|
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
|
import { doLdapLogin } from '../../../../../api/auth'
|
||||||
import { ApplicationState } from '../../../../../redux'
|
import { ApplicationState } from '../../../../../redux'
|
||||||
|
import { getAndSetUser } from '../../../../../utils/apiUtils'
|
||||||
|
|
||||||
export const ViaLdap: React.FC = () => {
|
export const ViaLdap: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { FormEvent, useState } from 'react'
|
import React, { FormEvent, useState } from 'react'
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
|
||||||
import { Alert, Button, Card, Form } from 'react-bootstrap'
|
import { Alert, Button, Card, Form } from 'react-bootstrap'
|
||||||
import { doOpenIdLogin } from '../../../../../api/user'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
|
import { doOpenIdLogin } from '../../../../../api/auth'
|
||||||
import { getAndSetUser } from '../../../../../utils/apiUtils'
|
import { getAndSetUser } from '../../../../../utils/apiUtils'
|
||||||
|
|
||||||
export const ViaOpenId: React.FC = () => {
|
export const ViaOpenId: React.FC = () => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { Fragment, useEffect, useRef, useState } from 'react'
|
import React, { Fragment, useEffect, useRef, useState } from 'react'
|
||||||
import { Button, Card, Modal } from 'react-bootstrap'
|
import { Button, Card, Modal } from 'react-bootstrap'
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { deleteUser } from '../../../../../api/user'
|
import { deleteUser } from '../../../../../api/me'
|
||||||
import { ForkAwesomeIcon } from '../../../../../fork-awesome/fork-awesome-icon'
|
import { ForkAwesomeIcon } from '../../../../../fork-awesome/fork-awesome-icon'
|
||||||
import { clearUser } from '../../../../../redux/user/methods'
|
import { clearUser } from '../../../../../redux/user/methods'
|
||||||
import { getBackendUrl } from '../../../../../utils/apiUtils'
|
import { getBackendUrl } from '../../../../../utils/apiUtils'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { ChangeEvent, FormEvent, useState } from 'react'
|
import React, { ChangeEvent, FormEvent, useState } from 'react'
|
||||||
import { Button, Card, Form } from 'react-bootstrap'
|
import { Button, Card, Form } from 'react-bootstrap'
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { changePassword } from '../../../../../api/user'
|
import { changePassword } from '../../../../../api/me'
|
||||||
|
|
||||||
export const ProfileChangePassword: React.FC = () => {
|
export const ProfileChangePassword: React.FC = () => {
|
||||||
useTranslation()
|
useTranslation()
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React, { ChangeEvent, FormEvent, useState } from 'react'
|
||||||
import { Button, Card, Form } from 'react-bootstrap'
|
import { Button, Card, Form } from 'react-bootstrap'
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import { updateDisplayName } from '../../../../../api/user'
|
import { updateDisplayName } from '../../../../../api/me'
|
||||||
import { ApplicationState } from '../../../../../redux'
|
import { ApplicationState } from '../../../../../redux'
|
||||||
import { getAndSetUser } from '../../../../../utils/apiUtils'
|
import { getAndSetUser } from '../../../../../utils/apiUtils'
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { getMe } from '../api/user'
|
import { getMe } from '../api/me'
|
||||||
import { LoginStatus } from '../redux/user/types'
|
|
||||||
import { setUser } from '../redux/user/methods'
|
import { setUser } from '../redux/user/methods'
|
||||||
|
import { LoginStatus } from '../redux/user/types'
|
||||||
import { store } from './store'
|
import { store } from './store'
|
||||||
|
|
||||||
export const getAndSetUser: () => (Promise<void>) = async () => {
|
export const getAndSetUser: () => (Promise<void>) = async () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue