fix: auth

This commit is contained in:
hippoz 2021-10-04 23:02:13 +03:00
parent 5eb1c2d0ae
commit 1720bee265
No known key found for this signature in database
GPG key ID: 7C52899193467641
3 changed files with 6 additions and 8 deletions

View file

@ -1,7 +1,7 @@
import config from '../config'; import config from '../config';
import { getToken } from "./tokenManager"; import { getToken } from "./tokenManager";
export async function APIRequest(endpoint, options) { export async function unauthenticated(endpoint, options) {
let res; let res;
let json; let json;
let isOK = false; let isOK = false;
@ -59,5 +59,3 @@ export async function authenticated(endpoint, options) {
return { res, json, isOK, err }; return { res, json, isOK, err };
}; };
export default APIRequest;

View file

@ -2,7 +2,7 @@ import { useState } from 'react';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import Notification from '../Notification'; import Notification from '../Notification';
import APIRequest from '../../api/request'; import { unauthenticated } from '../../api/request';
import { getSignupMessageFromError } from '../../common/util/errors' import { getSignupMessageFromError } from '../../common/util/errors'
export default function Create() { export default function Create() {
@ -16,7 +16,7 @@ export default function Create() {
const [ info, setInfo ] = useState(); const [ info, setInfo ] = useState();
const doCreateAccount = async () => { const doCreateAccount = async () => {
const { json, isOK } = await APIRequest('/api/v1/users/account/create', { const { json, isOK } = await unauthenticated('/api/v1/users/account/create', {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
@ -48,7 +48,7 @@ export default function Create() {
return; return;
} }
const { json, isOK } = await APIRequest('/api/v1/users/account/create/info', { const { json, isOK } = await unauthenticated('/api/v1/users/account/create/info', {
method: 'GET', method: 'GET',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',

View file

@ -2,7 +2,7 @@ import { useState } from 'react';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import Notification from '../Notification'; import Notification from '../Notification';
import APIRequest from '../../api/request'; import { unauthenticated } from '../../api/request';
import { login } from '../../api/authenticator'; import { login } from '../../api/authenticator';
import { setToken } from "../../api/tokenManager"; import { setToken } from "../../api/tokenManager";
import { getLoginMessageFromError } from '../../common/util/errors' import { getLoginMessageFromError } from '../../common/util/errors'
@ -21,7 +21,7 @@ export default function Login() {
return; return;
} }
const { json, isOK } = await APIRequest('/api/v1/users/token/create', { const { json, isOK } = await unauthenticated('/api/v1/users/token/create', {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',