feat: add setup wizard
This commit is contained in:
@@ -2,15 +2,22 @@ import { getCookie, setCookies } from "cookies-next";
|
||||
import * as jose from "jose";
|
||||
import api from "./api.service";
|
||||
|
||||
const signIn = async (email: string, password: string) => {
|
||||
const response = await api.post("auth/signIn", { email, password });
|
||||
const signIn = async (emailOrUsername: string, password: string) => {
|
||||
const emailOrUsernameBody = emailOrUsername.includes("@")
|
||||
? { email: emailOrUsername }
|
||||
: { username: emailOrUsername };
|
||||
|
||||
const response = await api.post("auth/signIn", {
|
||||
...emailOrUsernameBody,
|
||||
password,
|
||||
});
|
||||
setCookies("access_token", response.data.accessToken);
|
||||
setCookies("refresh_token", response.data.refreshToken);
|
||||
return response;
|
||||
};
|
||||
|
||||
const signUp = async (email: string, password: string) => {
|
||||
return await api.post("auth/signUp", { email, password });
|
||||
const signUp = async (email: string, username: string, password: string) => {
|
||||
return await api.post("auth/signUp", { email, username, password });
|
||||
};
|
||||
|
||||
const signOut = () => {
|
||||
|
||||
@@ -1,11 +1,24 @@
|
||||
import Config from "../types/config.type";
|
||||
import Config, { AdminConfig } from "../types/config.type";
|
||||
import api from "./api.service";
|
||||
|
||||
const getAll = async (): Promise<Config[]> => {
|
||||
const list = async (): Promise<Config[]> => {
|
||||
return (await api.get("/configs")).data;
|
||||
};
|
||||
|
||||
const listForAdmin = async (): Promise<AdminConfig[]> => {
|
||||
return (await api.get("/configs/admin")).data;
|
||||
};
|
||||
|
||||
const update = async (
|
||||
key: string,
|
||||
value: string | number | boolean
|
||||
): Promise<AdminConfig[]> => {
|
||||
return (await api.patch(`/configs/admin/${key}`, { value })).data;
|
||||
};
|
||||
|
||||
const get = (key: string, configVariables: Config[]): any => {
|
||||
if (!configVariables) return null;
|
||||
|
||||
const configVariable = configVariables.filter(
|
||||
(variable) => variable.key == key
|
||||
)[0];
|
||||
@@ -17,7 +30,14 @@ const get = (key: string, configVariables: Config[]): any => {
|
||||
if (configVariable.type == "string") return configVariable.value;
|
||||
};
|
||||
|
||||
export default {
|
||||
getAll,
|
||||
get,
|
||||
const finishSetup = async (): Promise<AdminConfig[]> => {
|
||||
return (await api.post("/configs/admin/finishSetup")).data;
|
||||
};
|
||||
|
||||
export default {
|
||||
list,
|
||||
listForAdmin,
|
||||
update,
|
||||
get,
|
||||
finishSetup,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user