diff --git a/src/api/auth.ts b/src/api/auth.ts new file mode 100644 index 000000000..87f1a890b --- /dev/null +++ b/src/api/auth.ts @@ -0,0 +1,40 @@ +import { expectResponseCode, getBackendUrl } from '../utils/apiUtils' +import { defaultFetchConfig } from './default' + +export const doEmailLogin = async (email: string, password: string): Promise => { + 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 => { + 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 => { + const response = await fetch(getBackendUrl() + '/auth/openid', { + ...defaultFetchConfig, + method: 'POST', + body: JSON.stringify({ + openId: openId + }) + }) + + expectResponseCode(response) +} diff --git a/src/api/user.ts b/src/api/me.ts similarity index 57% rename from src/api/user.ts rename to src/api/me.ts index 7c89c4225..fa8cb8c4f 100644 --- a/src/api/user.ts +++ b/src/api/me.ts @@ -15,44 +15,6 @@ export interface meResponse { provider: LoginProvider } -export const doEmailLogin = async (email: string, password: string): Promise => { - 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 => { - 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 => { - const response = await fetch(getBackendUrl() + '/auth/openid', { - ...defaultFetchConfig, - method: 'POST', - body: JSON.stringify({ - openId: openId - }) - }) - - expectResponseCode(response) -} - export const updateDisplayName = async (displayName: string): Promise => { const response = await fetch(getBackendUrl() + '/me', { ...defaultFetchConfig, diff --git a/src/components/landing/pages/login/auth/via-email.tsx b/src/components/landing/pages/login/auth/via-email.tsx index 909313d7d..bd13449ec 100644 --- a/src/components/landing/pages/login/auth/via-email.tsx +++ b/src/components/landing/pages/login/auth/via-email.tsx @@ -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 { 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' export const ViaEMail: React.FC = () => { diff --git a/src/components/landing/pages/login/auth/via-ldap.tsx b/src/components/landing/pages/login/auth/via-ldap.tsx index 5cfc1e90b..aa36c0892 100644 --- a/src/components/landing/pages/login/auth/via-ldap.tsx +++ b/src/components/landing/pages/login/auth/via-ldap.tsx @@ -1,11 +1,11 @@ import React, { FormEvent, useState } from 'react' +import { Alert, Button, Card, Form } from 'react-bootstrap' 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 { doLdapLogin } from '../../../../../api/auth' import { ApplicationState } from '../../../../../redux' +import { getAndSetUser } from '../../../../../utils/apiUtils' export const ViaLdap: React.FC = () => { const { t } = useTranslation() diff --git a/src/components/landing/pages/login/auth/via-openid.tsx b/src/components/landing/pages/login/auth/via-openid.tsx index fe37610ed..4f9c33326 100644 --- a/src/components/landing/pages/login/auth/via-openid.tsx +++ b/src/components/landing/pages/login/auth/via-openid.tsx @@ -1,7 +1,7 @@ import React, { FormEvent, useState } from 'react' -import { Trans, useTranslation } from 'react-i18next' 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' export const ViaOpenId: React.FC = () => { diff --git a/src/components/landing/pages/profile/settings/profile-account-management.tsx b/src/components/landing/pages/profile/settings/profile-account-management.tsx index c46d7b65c..f49aaaf55 100644 --- a/src/components/landing/pages/profile/settings/profile-account-management.tsx +++ b/src/components/landing/pages/profile/settings/profile-account-management.tsx @@ -1,7 +1,7 @@ import React, { Fragment, useEffect, useRef, useState } from 'react' import { Button, Card, Modal } from 'react-bootstrap' 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 { clearUser } from '../../../../../redux/user/methods' import { getBackendUrl } from '../../../../../utils/apiUtils' diff --git a/src/components/landing/pages/profile/settings/profile-change-password.tsx b/src/components/landing/pages/profile/settings/profile-change-password.tsx index 1cd6e3838..616420cf9 100644 --- a/src/components/landing/pages/profile/settings/profile-change-password.tsx +++ b/src/components/landing/pages/profile/settings/profile-change-password.tsx @@ -1,7 +1,7 @@ import React, { ChangeEvent, FormEvent, useState } from 'react' import { Button, Card, Form } from 'react-bootstrap' import { Trans, useTranslation } from 'react-i18next' -import { changePassword } from '../../../../../api/user' +import { changePassword } from '../../../../../api/me' export const ProfileChangePassword: React.FC = () => { useTranslation() diff --git a/src/components/landing/pages/profile/settings/profile-display-name.tsx b/src/components/landing/pages/profile/settings/profile-display-name.tsx index 2276a3d9d..a2c875f79 100644 --- a/src/components/landing/pages/profile/settings/profile-display-name.tsx +++ b/src/components/landing/pages/profile/settings/profile-display-name.tsx @@ -2,7 +2,7 @@ import React, { ChangeEvent, FormEvent, useState } from 'react' import { Button, Card, Form } from 'react-bootstrap' import { Trans, useTranslation } from 'react-i18next' import { useSelector } from 'react-redux' -import { updateDisplayName } from '../../../../../api/user' +import { updateDisplayName } from '../../../../../api/me' import { ApplicationState } from '../../../../../redux' import { getAndSetUser } from '../../../../../utils/apiUtils' diff --git a/src/utils/apiUtils.ts b/src/utils/apiUtils.ts index ce3aabf93..99342f8af 100644 --- a/src/utils/apiUtils.ts +++ b/src/utils/apiUtils.ts @@ -1,6 +1,6 @@ -import { getMe } from '../api/user' -import { LoginStatus } from '../redux/user/types' +import { getMe } from '../api/me' import { setUser } from '../redux/user/methods' +import { LoginStatus } from '../redux/user/types' import { store } from './store' export const getAndSetUser: () => (Promise) = async () => {