Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default root login #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions backend/endpoints/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ function authenticationEndpoints(app) {
return;
}

const onboardingUser = await User.get({ role: "root" });
if (!onboardingUser) {
response.status(200).json({ completed: true });
return;
}

await Telemetry.sendTelemetry("onboarding_complete"); // Have to send here since we have no other hooks.
response.status(200).json({
valid: true,
Expand Down Expand Up @@ -53,19 +47,6 @@ function authenticationEndpoints(app) {
return;
}

if (email === process.env.SYS_EMAIL) {
const completeSetup = (await User.count({ role: "admin" })) > 0;
if (completeSetup) {
response.status(200).json({
user: null,
valid: false,
token: null,
message: "[004] Invalid login credentials.",
});
return;
}
}

const existingUser = await User.get({ email: email });
if (!existingUser) {
response.status(200).json({
Expand Down
11 changes: 11 additions & 0 deletions backend/endpoints/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ process.env.NODE_ENV === "development"
? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` })
: require("dotenv").config();
const { SystemSettings } = require("../models/systemSettings");
const { User } = require("../models/user");
const { systemInit } = require("../utils/boot");
const { dumpENV } = require("../utils/env");
const { reqBody, userFromSession } = require("../utils/http");
Expand Down Expand Up @@ -125,6 +126,16 @@ function systemEndpoints(app) {
}
);

app.get("/system/onboarding-complete", async (_, response) => {
try {
const completeSetup = (await User.count({ role: "admin" })) > 0;
response.status(200).json({ completed: completeSetup });
} catch (e) {
console.log(e.message, e);
response.sendStatus(500).end();
}
});

app.get("/boot", async (_, response) => {
try {
await systemInit();
Expand Down
26 changes: 0 additions & 26 deletions backend/utils/boot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ process.env.NODE_ENV === "development"
: require("dotenv").config();

const { Telemetry } = require("../../models/telemetry");
const { User } = require("../../models/user");
const { getGitVersion } = require("../metrics");

function setupVectorCacheStorage() {
Expand Down Expand Up @@ -45,31 +44,6 @@ async function systemInit() {
try {
setupVectorCacheStorage();
await setupTelemetry();
const completeSetup = (await User.count({ role: "admin" })) > 0;
if (completeSetup) return;

process.env.SYS_EMAIL = "root@vectoradmin.com";
process.env.SYS_PASSWORD = "password";

const existingRootUser = await User.get({
email: process.env.SYS_EMAIL,
role: "root",
});
if (existingRootUser) return;

const rootUser = await User.create({
email: process.env.SYS_EMAIL,
password: process.env.SYS_PASSWORD,
role: "root",
});

if (!rootUser) {
console.error("FAILED TO CREATE ROOT USER!", message);
return;
}

console.log("Root user created with credentials");
return;
} catch (e) {
console.error("systemInit", e.message, e);
return;
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/models/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ const System = {
return null;
});
},
onboardingComplete: async (): Promise<boolean> => {
return fetch(`${API_BASE}/system/onboarding-complete`, {
method: 'GET',
cache: 'no-cache',
})
.then((res) => res.json())
.then((res) => res.completed)
.catch((e) => {
console.error(e);
return false;
});
},
};

export default System;
14 changes: 11 additions & 3 deletions frontend/src/pages/Authentication/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import User from '@/models/user';
import { APP_NAME, STORE_TOKEN, STORE_USER } from '@/utils/constants';
import paths from '@/utils/paths';
import validateSessionTokenForUser from '@/utils/session';
import System from '@/models/system';

type IStages = 'loading' | 'failed' | 'success' | 'ready';
type FormTypes = {
Expand Down Expand Up @@ -52,12 +53,19 @@ const SignIn = () => {
if (!!token && !!user) {
window.localStorage.setItem(STORE_USER, JSON.stringify(user));
window.localStorage.setItem(STORE_TOKEN, token);
window.location.replace(
user.role === 'root' ? paths.onboardingSetup() : paths.dashboard()
);
window.location.replace(paths.dashboard());
}
};

useEffect(() => {
async function checkOnboardingComplete() {
const completed = await System.onboardingComplete();
if (completed) return;
window.location.replace(paths.onboardingSetup());
}
checkOnboardingComplete();
}, []);

useEffect(() => {
async function checkAuth() {
const currentToken = window.localStorage.getItem(STORE_TOKEN);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/DocumentView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ const CopyDocToModal = memo(
className="rounded-lg border border-white/10 bg-main-2 px-2 py-2 text-white/60"
>
{workspaces
.filter((ws) => ws.id !== workspace.id)
.filter((ws) => ws.id !== workspace?.id)
.map((ws: any) => {
return <option value={ws.id}>{ws.name}</option>;
})}
Expand Down