Migrate server setup functionality

Changes:
- Check if admin is set up
- Redirect to admin setup if not already done
- Create admin password
- Login as admin and get access token for future requests
- Add a router for setup
- Middleware to prevent any route from being accessible on the server till the admin setup is done

GitLab: #80
GitLab: #73

Change-Id: I8b7ecab68f6b4d5c6313ce2e72a4ae4fdef9eda0
diff --git a/client/src/App.tsx b/client/src/App.tsx
index 3f95af2..c202c37 100644
--- a/client/src/App.tsx
+++ b/client/src/App.tsx
@@ -16,9 +16,27 @@
  * <https://www.gnu.org/licenses/>.
  */
 import { useState } from 'react';
-import { Outlet } from 'react-router-dom';
+import { json, LoaderFunctionArgs, Outlet, redirect } from 'react-router-dom';
 
 import WelcomeAnimation from './components/welcome';
+import { apiUrl } from './utils/constants';
+
+export async function checkSetupStatus(): Promise<boolean> {
+  const url = new URL('/setup/check', apiUrl);
+  const response = await fetch(url);
+  const { isSetupComplete } = await response.json();
+  return isSetupComplete;
+}
+
+export async function appLoader({ request }: LoaderFunctionArgs) {
+  const initialUrl = new URL(request.url);
+  const isSetupComplete = await checkSetupStatus();
+
+  if (!isSetupComplete && initialUrl.pathname !== '/setup/login') {
+    return redirect('/setup/login');
+  }
+  return json({ isSetupComplete }, { status: 200 });
+}
 
 const App = () => {
   const [displayWelcome, setDisplayWelcome] = useState<boolean>(true);