arrow functions

This commit is contained in:
Aarni Halinen
2022-01-14 00:46:41 +02:00
parent 8fb4dd9000
commit 44ccdd87de
13 changed files with 97 additions and 101 deletions
+4 -4
View File
@@ -1,12 +1,12 @@
import { deleteTokenCookie, getTokenCookie } from "@utils/auth"; import { deleteTokenCookie, getTokenCookie } from "@utils/auth";
import { APIPath, postBackendAPI } from "./backend"; import { APIPath, postBackendAPI } from "./backend";
export async function generateToken(username: string, password: string): Promise<string> { export const generateToken = async (username: string, password: string): Promise<string> => {
const { token } = await postBackendAPI<{ username: string, password: string }, { token: string }>({ path: APIPath.AUTH_TOKEN }, { username, password }); const { token } = await postBackendAPI<{ username: string, password: string }, { token: string }>({ path: APIPath.AUTH_TOKEN }, { username, password });
return token; return token;
} };
export async function isAuthenticated(): Promise<boolean> { export const authenticate = async (): Promise<boolean> => {
try { try {
const token = getTokenCookie(); const token = getTokenCookie();
await postBackendAPI({ path: APIPath.AUTH_TOKEN_VERIFY }, { token }); await postBackendAPI({ path: APIPath.AUTH_TOKEN_VERIFY }, { token });
@@ -16,4 +16,4 @@ export async function isAuthenticated(): Promise<boolean> {
deleteTokenCookie(); deleteTokenCookie();
return false; return false;
} }
} };
+15 -15
View File
@@ -71,14 +71,14 @@ const fillUrlParams = (apiPath: APIPath, params: API["urlParams"] = {}): string
return `/${path}`; return `/${path}`;
}; };
async function callBackendAPI<RequestType, ResponseType>( const callBackendAPI = async <RequestType, ResponseType>(
path: APIPath, path: APIPath,
urlParams: API["urlParams"] = {}, urlParams: API["urlParams"] = {},
queryParams: API["queryParams"] = {}, queryParams: API["queryParams"] = {},
method: AxiosRequestConfig["method"], method: AxiosRequestConfig["method"],
headers: Headers, headers: Headers,
requestBody: RequestType, requestBody: RequestType,
): Promise<ResponseType> { ): Promise<ResponseType> => {
const url = fillUrlParams(path, urlParams); const url = fillUrlParams(path, urlParams);
const request: AxiosRequestConfig = { const request: AxiosRequestConfig = {
url, url,
@@ -95,32 +95,32 @@ async function callBackendAPI<RequestType, ResponseType>(
return arrayResp.results; return arrayResp.results;
} }
return response.data; return response.data;
} };
export async function getBackendAPI<ResponseType>({ export const getBackendAPI = async <ResponseType>({
path, urlParams, queryParams, authenticated, path, urlParams, queryParams, authenticated,
}: API): Promise<ResponseType> { }: API): Promise<ResponseType> => {
const headers = getHeaders(authenticated); const headers = getHeaders(authenticated);
return callBackendAPI<undefined, ResponseType>(path, urlParams, queryParams, "GET", headers, undefined); return callBackendAPI<undefined, ResponseType>(path, urlParams, queryParams, "GET", headers, undefined);
} };
export async function postBackendAPI<RequestType, ResponseType>({ export const postBackendAPI = async <RequestType, ResponseType>({
path, urlParams, queryParams, authenticated, path, urlParams, queryParams, authenticated,
}: API, body: RequestType): Promise<ResponseType> { }: API, body: RequestType): Promise<ResponseType> => {
const headers = getHeaders(authenticated); const headers = getHeaders(authenticated);
return callBackendAPI<RequestType, ResponseType>(path, urlParams, queryParams, "POST", headers, body); return callBackendAPI<RequestType, ResponseType>(path, urlParams, queryParams, "POST", headers, body);
} };
export async function putBackendAPI<RequestType, ResponseType>({ export const putBackendAPI = async <RequestType, ResponseType>({
path, urlParams, queryParams, authenticated, path, urlParams, queryParams, authenticated,
}: API, body: RequestType): Promise<ResponseType> { }: API, body: RequestType): Promise<ResponseType> => {
const headers = getHeaders(authenticated); const headers = getHeaders(authenticated);
return callBackendAPI<RequestType, ResponseType>(path, urlParams, queryParams, "PUT", headers, body); return callBackendAPI<RequestType, ResponseType>(path, urlParams, queryParams, "PUT", headers, body);
} };
export async function deleteBackendAPI<ResponseType>({ export const deleteBackendAPI = async <ResponseType>({
path, urlParams, queryParams, authenticated, path, urlParams, queryParams, authenticated,
}: API): Promise<ResponseType> { }: API): Promise<ResponseType> => {
const headers = getHeaders(authenticated); const headers = getHeaders(authenticated);
return callBackendAPI<undefined, ResponseType>(path, urlParams, queryParams, "DELETE", headers, undefined); return callBackendAPI<undefined, ResponseType>(path, urlParams, queryParams, "DELETE", headers, undefined);
} };
+11 -11
View File
@@ -12,7 +12,7 @@ interface Options {
} }
class EventApi { class EventApi {
static async getEvent(id: number, auth = false): Promise<Event> { static getEvent = async (id: number, auth = false): Promise<Event> => {
try { try {
return await getBackendAPI<Event>({ return await getBackendAPI<Event>({
path: APIPath.EVENTS, urlParams: { id }, authenticated: auth, path: APIPath.EVENTS, urlParams: { id }, authenticated: auth,
@@ -21,11 +21,11 @@ class EventApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async getEvents({ static getEvents = async ({
since, limit, offset, auth, since, limit, offset, auth,
}: Options = {}): Promise<Event[]> { }: Options = {}): Promise<Event[]> => {
try { try {
return await getBackendAPI<Event[]>({ return await getBackendAPI<Event[]>({
path: APIPath.EVENTS, path: APIPath.EVENTS,
@@ -40,9 +40,9 @@ class EventApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async createEvent(data: Event): Promise<Event> { static createEvent = async (data: Event): Promise<Event> => {
try { try {
return await postBackendAPI<Event, Event>({ return await postBackendAPI<Event, Event>({
path: APIPath.EVENTS, authenticated: true, path: APIPath.EVENTS, authenticated: true,
@@ -51,9 +51,9 @@ class EventApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async updateEvent(data: Event): Promise<Event> { static updateEvent = async (data: Event): Promise<Event> => {
try { try {
return await putBackendAPI<Event, Event>({ return await putBackendAPI<Event, Event>({
path: APIPath.EVENTS, urlParams: { id: data.id }, authenticated: true, path: APIPath.EVENTS, urlParams: { id: data.id }, authenticated: true,
@@ -62,16 +62,16 @@ class EventApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async deleteEvent(id: number): Promise<void> { static deleteEvent = async (id: number): Promise<void> => {
try { try {
await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.EVENTS, urlParams: { id }, authenticated: true }); await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.EVENTS, urlParams: { id }, authenticated: true });
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
} }
export default EventApi; export default EventApi;
+10 -10
View File
@@ -11,7 +11,7 @@ interface Options {
} }
class FeedApi { class FeedApi {
static async getPost(id: number, auth?: boolean): Promise<Post> { static getPost = async (id: number, auth?: boolean): Promise<Post> => {
try { try {
return await getBackendAPI<Post>({ return await getBackendAPI<Post>({
path: APIPath.FEED, urlParams: { id }, authenticated: auth, path: APIPath.FEED, urlParams: { id }, authenticated: auth,
@@ -20,9 +20,9 @@ class FeedApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async getFeed({ limit, offset, auth }: Options = {}): Promise<Post[]> { static getFeed = async ({ limit, offset, auth }: Options = {}): Promise<Post[]> => {
try { try {
return await getBackendAPI<Post[]>({ return await getBackendAPI<Post[]>({
path: APIPath.FEED, path: APIPath.FEED,
@@ -36,18 +36,18 @@ class FeedApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async createPost(data: Post): Promise<Post> { static createPost = async (data: Post): Promise<Post> => {
try { try {
return await postBackendAPI<Post, Post>({ path: APIPath.FEED, authenticated: true }, data); return await postBackendAPI<Post, Post>({ path: APIPath.FEED, authenticated: true }, data);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async updatePost(data: Post): Promise<Post> { static updatePost = async (data: Post): Promise<Post> => {
try { try {
return await putBackendAPI<Post, Post>({ return await putBackendAPI<Post, Post>({
path: APIPath.FEED, urlParams: { id: data.id }, authenticated: true, path: APIPath.FEED, urlParams: { id: data.id }, authenticated: true,
@@ -56,16 +56,16 @@ class FeedApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async deletePost(id: number): Promise<void> { static deletePost = async (id: number): Promise<void> => {
try { try {
await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.EVENTS, urlParams: { id }, authenticated: true }); await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.EVENTS, urlParams: { id }, authenticated: true });
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
} }
export default FeedApi; export default FeedApi;
+11 -11
View File
@@ -12,7 +12,7 @@ interface Options {
} }
class JobAdApi { class JobAdApi {
static async getJobAd(id: number, auth = false): Promise<JobAd> { static getJobAd = async (id: number, auth = false): Promise<JobAd> => {
try { try {
return await getBackendAPI({ return await getBackendAPI({
path: APIPath.JOBADS, urlParams: { id }, authenticated: auth, path: APIPath.JOBADS, urlParams: { id }, authenticated: auth,
@@ -21,11 +21,11 @@ class JobAdApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async getJobAds({ static getJobAds = async ({
since, limit, offset, auth, since, limit, offset, auth,
}: Options = {}): Promise<JobAd[]> { }: Options = {}): Promise<JobAd[]> => {
try { try {
return await getBackendAPI<JobAd[]>({ return await getBackendAPI<JobAd[]>({
path: APIPath.JOBADS, path: APIPath.JOBADS,
@@ -40,9 +40,9 @@ class JobAdApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async createJobAd(data: JobAd): Promise<JobAd> { static createJobAd = async (data: JobAd): Promise<JobAd> => {
try { try {
return await postBackendAPI<JobAd, JobAd>({ return await postBackendAPI<JobAd, JobAd>({
path: APIPath.JOBADS, authenticated: true, path: APIPath.JOBADS, authenticated: true,
@@ -51,9 +51,9 @@ class JobAdApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async updateJobAd(data: JobAd): Promise<JobAd> { static updateJobAd = async (data: JobAd): Promise<JobAd> => {
try { try {
return await putBackendAPI<JobAd, JobAd>({ return await putBackendAPI<JobAd, JobAd>({
path: APIPath.JOBADS, urlParams: { id: data.id }, authenticated: true, path: APIPath.JOBADS, urlParams: { id: data.id }, authenticated: true,
@@ -62,16 +62,16 @@ class JobAdApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async deleteJobAd(id: number): Promise<void> { static deleteJobAd = async (id: number): Promise<void> => {
try { try {
await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.JOBADS, urlParams: { id }, authenticated: true }); await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.JOBADS, urlParams: { id }, authenticated: true });
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
} }
export default JobAdApi; export default JobAdApi;
+24 -24
View File
@@ -11,7 +11,7 @@ export type EmailRequest = {
}; };
class SignupApi { class SignupApi {
static async getSignup(id: number): Promise<Signup> { static getSignup = async (id: number): Promise<Signup> => {
try { try {
return await getBackendAPI<Signup>({ return await getBackendAPI<Signup>({
path: APIPath.SIGNUPS, urlParams: { id }, authenticated: true, path: APIPath.SIGNUPS, urlParams: { id }, authenticated: true,
@@ -20,9 +20,9 @@ class SignupApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async createSignup(data: Signup): Promise<Signup> { static createSignup = async (data: Signup): Promise<Signup> => {
try { try {
return await postBackendAPI<Signup, Signup>({ return await postBackendAPI<Signup, Signup>({
path: APIPath.SIGNUPS, path: APIPath.SIGNUPS,
@@ -31,9 +31,9 @@ class SignupApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async updateSignup(data: Signup, uuid: string): Promise<Signup> { static updateSignup = async (data: Signup, uuid: string): Promise<Signup> => {
try { try {
const { id } = data; const { id } = data;
if (!id) throw new Error("SignupId required!"); if (!id) throw new Error("SignupId required!");
@@ -48,9 +48,9 @@ class SignupApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async getSignupUUID(id: number, uuid: string): Promise<Signup> { static getSignupUUID = async (id: number, uuid: string): Promise<Signup> => {
try { try {
return await getBackendAPI<Signup>({ return await getBackendAPI<Signup>({
path: APIPath.SIGNUPS_EDIT, path: APIPath.SIGNUPS_EDIT,
@@ -63,18 +63,18 @@ class SignupApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async deleteSignup(id: number): Promise<void> { static deleteSignup = async (id: number): Promise<void> => {
try { try {
await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.SIGNUPS, urlParams: { id }, authenticated: true }); await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.SIGNUPS, urlParams: { id }, authenticated: true });
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async getForm(id: number, auth = false): Promise<SignupForm> { static getForm = async (id: number, auth = false): Promise<SignupForm> => {
try { try {
return await getBackendAPI<SignupForm>({ return await getBackendAPI<SignupForm>({
path: APIPath.SIGNUP_FORMS, urlParams: { id }, authenticated: auth, path: APIPath.SIGNUP_FORMS, urlParams: { id }, authenticated: auth,
@@ -83,9 +83,9 @@ class SignupApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async getForms(auth = false): Promise<SignupForm[]> { static getForms = async (auth = false): Promise<SignupForm[]> => {
try { try {
return await getBackendAPI<SignupForm[]>({ return await getBackendAPI<SignupForm[]>({
path: APIPath.SIGNUP_FORMS, authenticated: auth, path: APIPath.SIGNUP_FORMS, authenticated: auth,
@@ -94,9 +94,9 @@ class SignupApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async createForm(data: SignupForm): Promise<SignupForm> { static createForm = async (data: SignupForm): Promise<SignupForm> => {
try { try {
return await postBackendAPI<SignupForm, SignupForm>({ return await postBackendAPI<SignupForm, SignupForm>({
path: APIPath.SIGNUP_FORMS, authenticated: true, path: APIPath.SIGNUP_FORMS, authenticated: true,
@@ -105,9 +105,9 @@ class SignupApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async updateForm(data: SignupForm): Promise<SignupForm> { static updateForm = async (data: SignupForm): Promise<SignupForm> => {
try { try {
return await putBackendAPI<SignupForm, SignupForm>({ return await putBackendAPI<SignupForm, SignupForm>({
path: APIPath.SIGNUP_FORMS, urlParams: { id: data.id }, authenticated: true, path: APIPath.SIGNUP_FORMS, urlParams: { id: data.id }, authenticated: true,
@@ -116,34 +116,34 @@ class SignupApi {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async deleteForm(id: number): Promise<void> { static deleteForm = async (id: number): Promise<void> => {
try { try {
await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.SIGNUP_FORMS, urlParams: { id }, authenticated: true }); await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.SIGNUP_FORMS, urlParams: { id }, authenticated: true });
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async signupFormSendEmail(data: EmailRequest, id: number): Promise<void> { static signupFormSendEmail = async (data: EmailRequest, id: number): Promise<void> => {
try { try {
await postBackendAPI<EmailRequest, { message: "Email sent" }>({ path: APIPath.SIGNUP_FORMS_EMAIL, urlParams: { id }, authenticated: true }, data); await postBackendAPI<EmailRequest, { message: "Email sent" }>({ path: APIPath.SIGNUP_FORMS_EMAIL, urlParams: { id }, authenticated: true }, data);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
static async getSignups(id: number): Promise<Signup[]> { static getSignups = async (id: number): Promise<Signup[]> => {
try { try {
return await getBackendAPI<Signup[]>({ path: APIPath.SIGNUP_FORMS_SIGNUPS, urlParams: { id }, authenticated: true }); return await getBackendAPI<Signup[]>({ path: APIPath.SIGNUP_FORMS_SIGNUPS, urlParams: { id }, authenticated: true });
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
} }
export default SignupApi; export default SignupApi;
+2 -2
View File
@@ -3,14 +3,14 @@ import Tag from "@models/Tag";
import { APIPath, getBackendAPI } from "./backend"; import { APIPath, getBackendAPI } from "./backend";
class TagApi { class TagApi {
static async getTags(): Promise<Tag[]> { static getTags = async (): Promise<Tag[]> => {
try { try {
return await getBackendAPI<Tag[]>({ path: APIPath.TAGS }); return await getBackendAPI<Tag[]>({ path: APIPath.TAGS });
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
} }
} };
} }
export default TagApi; export default TagApi;
@@ -5,17 +5,15 @@ import Checkbox from "./Checkbox";
// See https://github.com/rjsf-team/react-jsonschema-form/blob/master/packages/core/src/components/widgets/CheckboxesWidget.js // See https://github.com/rjsf-team/react-jsonschema-form/blob/master/packages/core/src/components/widgets/CheckboxesWidget.js
function selectValue(value, selected, all) { const selectValue = (value, selected, all) => {
const at = all.indexOf(value); const at = all.indexOf(value);
const updated = selected.slice(0, at).concat(value, selected.slice(at)); const updated = selected.slice(0, at).concat(value, selected.slice(at));
// As inserting values at predefined index positions doesn't work with empty // As inserting values at predefined index positions doesn't work with empty
// arrays, we need to reorder the updated selection to match the initial order // arrays, we need to reorder the updated selection to match the initial order
return updated.sort((a, b) => all.indexOf(a) > all.indexOf(b)); return updated.sort((a, b) => all.indexOf(a) > all.indexOf(b));
} };
function deselectValue(value, selected) { const deselectValue = (value, selected) => selected.filter((v) => v !== value);
return selected.filter((v) => v !== value);
}
type CheckboxesProps = Omit<WidgetProps, "options"> & { type CheckboxesProps = Omit<WidgetProps, "options"> & {
options: any; options: any;
+4 -4
View File
@@ -1,7 +1,7 @@
import useSWR from "swr"; import useSWR from "swr";
import { APIPath, getBackendAPI } from "@api/backend"; import { APIPath, getBackendAPI } from "@api/backend";
function useFetchBackend<DataType>({ const useFetchBackend = <DataType>({
apiPath: path, apiPath: path,
fallbackData, fallbackData,
options, options,
@@ -14,14 +14,14 @@ function useFetchBackend<DataType>({
} }
}): { }): {
data?: DataType, data?: DataType,
error?: any error?: Error
} { } => {
const fetcher = (limit: number, authenticated: boolean) => getBackendAPI<DataType>({ path, queryParams: { limit }, authenticated }); const fetcher = (limit: number, authenticated: boolean) => getBackendAPI<DataType>({ path, queryParams: { limit }, authenticated });
const { data, error } = useSWR([options?.limit, options?.auth], fetcher, { fallbackData }); const { data, error } = useSWR([options?.limit, options?.auth], fetcher, { fallbackData });
return { return {
data, data,
error, error,
}; };
} };
export default useFetchBackend; export default useFetchBackend;
+2 -2
View File
@@ -6,7 +6,7 @@ import { ServerStyleSheet } from "styled-components";
import Favicons from "@components/Favicons"; import Favicons from "@components/Favicons";
export default class MyDocument extends Document<{ styleTags: unknown }> { export default class MyDocument extends Document<{ styleTags: unknown }> {
static async getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps> { static getInitialProps = async (ctx: DocumentContext): Promise<DocumentInitialProps> => {
const sheet = new ServerStyleSheet(); const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage; const originalRenderPage = ctx.renderPage;
try { try {
@@ -26,7 +26,7 @@ export default class MyDocument extends Document<{ styleTags: unknown }> {
} finally { } finally {
sheet.seal(); sheet.seal();
} }
} };
render(): JSX.Element { render(): JSX.Element {
const { styleTags } = this.props; const { styleTags } = this.props;
+3 -3
View File
@@ -3,7 +3,7 @@ import { NextPage } from "next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import styled from "styled-components"; import styled from "styled-components";
import { setTokenCookie } from "@utils/auth"; import { setTokenCookie } from "@utils/auth";
import { generateToken, isAuthenticated } from "@api/auth"; import { generateToken, authenticate } from "@api/auth";
import AdminPageWrapper from "@views/common/AdminPageWrapper"; import AdminPageWrapper from "@views/common/AdminPageWrapper";
const Main = styled.div` const Main = styled.div`
@@ -21,8 +21,8 @@ const AdminLoginPage: NextPage = () => {
const next = router.query.next as string || DEFAULT_REDIRECT; const next = router.query.next as string || DEFAULT_REDIRECT;
useEffect(() => { useEffect(() => {
isAuthenticated().then((res) => { authenticate().then((authResult) => {
if (res) { if (authResult) {
router.push(next); router.push(next);
} }
}); });
+5 -7
View File
@@ -1,15 +1,13 @@
import Cookies from "js-cookie"; import Cookies from "js-cookie";
export function setTokenCookie(token: string): void { export const setTokenCookie = (token: string): void => {
Cookies.set("jwt", token); Cookies.set("jwt", token);
Cookies.set("jwt", token, { domain: ".sahkoinsinoorikilta.fi" }); Cookies.set("jwt", token, { domain: ".sahkoinsinoorikilta.fi" });
} };
export function getTokenCookie(): string { export const getTokenCookie = (): string => Cookies.get("jwt");
return Cookies.get("jwt");
}
export function deleteTokenCookie(): void { export const deleteTokenCookie = (): void => {
Cookies.remove("jwt", { domain: ".sahkoinsinoorikilta.fi" }); Cookies.remove("jwt", { domain: ".sahkoinsinoorikilta.fi" });
Cookies.remove("jwt"); Cookies.remove("jwt");
} };
+3 -3
View File
@@ -5,7 +5,7 @@ import colors from "@theme/colors";
import breakpoints from "@theme/breakpoints"; import breakpoints from "@theme/breakpoints";
import AdminHeader from "@components/AdminHeader"; import AdminHeader from "@components/AdminHeader";
import AdminSidebar from "@components/AdminSidebar"; import AdminSidebar from "@components/AdminSidebar";
import { isAuthenticated } from "@api/auth"; import { authenticate } from "@api/auth";
import LoadingView from "./LoadingView"; import LoadingView from "./LoadingView";
const Main = styled.main` const Main = styled.main`
@@ -43,8 +43,8 @@ const useShouldRedirect = (enabled = true) => {
useEffect(() => { useEffect(() => {
if (enabled) { if (enabled) {
isAuthenticated().then((result) => { authenticate().then((authResult) => {
setRedirect(!result); setRedirect(!authResult);
setCompleted(true); setCompleted(true);
}); });
} }