lincd-cli 0.2.41 → 0.2.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ <component name="ProjectRunConfigurationManager">
2
+ <configuration default="false" name="start" type="js.build_tools.npm" nameIsGenerated="true">
3
+ <package-json value="$PROJECT_DIR$/package.json" />
4
+ <command value="run" />
5
+ <scripts>
6
+ <script value="start" />
7
+ </scripts>
8
+ <node-interpreter value="project" />
9
+ <envs />
10
+ <method v="2" />
11
+ </configuration>
12
+ </component>
@@ -59,6 +59,7 @@
59
59
  "@babel/register": "^7.22.5",
60
60
  "chalk": "4.1.2",
61
61
  "lincd": "^0.5.22",
62
+ "lincd-auth": "^0.1.19",
62
63
  "lincd-jsonld": "^0.1.21",
63
64
  "lincd-server": "^0.1.39",
64
65
  "lincd-server-utils": "^0.1.7",
@@ -9,8 +9,13 @@ export function Header() {
9
9
  <header className={style.header}>
10
10
  <h1>${name}</h1>
11
11
  <nav className={style.menu}>
12
- {Object.keys(ROUTES).map(key => {
13
- return <Link key={key} to={ROUTES[key].path}>{ROUTES[key].label || key}</Link>
12
+ {Object.keys(ROUTES).map((key) => {
13
+ if (ROUTES[key].excludeFromMenu) return null;
14
+ return (
15
+ <Link key={key} to={ROUTES[key].path}>
16
+ {ROUTES[key].label || key}
17
+ </Link>
18
+ );
14
19
  })}
15
20
  </nav>
16
21
  </header>
@@ -0,0 +1,11 @@
1
+ import {DefaultLayout} from '../layout/DefaultLayout';
2
+
3
+ export default function PageNotFound() {
4
+ return (
5
+ <DefaultLayout>
6
+ <div>
7
+ <h2>Page not found</h2>
8
+ </div>
9
+ </DefaultLayout>
10
+ );
11
+ }
@@ -0,0 +1,12 @@
1
+ import {DefaultLayout} from '../layout/DefaultLayout';
2
+
3
+ export default function Signin() {
4
+ return (
5
+ <DefaultLayout>
6
+ <div>
7
+ <h2>Sign In</h2>
8
+ See lincd.org for different ways to sign in.
9
+ </div>
10
+ </DefaultLayout>
11
+ );
12
+ }
@@ -1,21 +1,36 @@
1
1
  import React, {lazy, Suspense} from 'react';
2
2
  import {Route, Routes} from 'react-router-dom';
3
3
  import {Spinner} from './components/Spinner';
4
+ import {RequireAuth} from 'lincd-auth/lib/components/RequireAuth';
5
+ import PageNotFound from './pages/PageNotFound';
4
6
 
5
7
  //In React 18 you can use 'lazy' to import pages only when you need them.
6
8
  //This will cause webpack to create multiple bundles, and the right bundles are automatically loaded
7
-
8
- export const ROUTES = {
9
+ interface RouteObj {
10
+ path: string;
11
+ component?: React.LazyExoticComponent<() => JSX.Element>;
12
+ render?: () => JSX.Element;
13
+ requireAuth?: boolean;
14
+ excludeFromMenu?: boolean;
15
+ label?: string;
16
+ }
17
+ export const ROUTES: {[key: string]: RouteObj} = {
9
18
  index: {
10
19
  path: '/',
11
20
  component: lazy(() => import('./pages/Home' /* webpackPrefetch: true */)),
12
- requireAuth: true,
13
- label:"Home",
21
+ label: 'Home',
14
22
  },
15
23
  page1: {
16
24
  path: '/page1',
17
25
  component: lazy(() => import('./pages/Page1' /* webpackPrefetch: true */)),
18
- label:"Page 1",
26
+ label: 'Protected page',
27
+ requireAuth: true,
28
+ },
29
+ signin: {
30
+ path: '/signin',
31
+ component: lazy(() => import('./pages/Signin' /* webpackPrefetch: true */)),
32
+ label: 'Sign In',
33
+ excludeFromMenu: true,
19
34
  },
20
35
  };
21
36
 
@@ -25,18 +40,33 @@ export default function AppRoutes() {
25
40
  {Object.keys(ROUTES).map((routeName) => {
26
41
  const route = ROUTES[routeName];
27
42
  const Component = route.component;
43
+
44
+ //if a route is marked as requireAuth, wrap it in the RequireAuth component and pass the signinRoute
45
+ const AuthGuard = route.requireAuth ? RequireAuth : React.Fragment;
46
+ const authProps = route.requireAuth
47
+ ? {signinRoute: ROUTES.signin.path}
48
+ : {};
49
+
50
+ // define a render function that determines what to render based on the component and route.render
51
+ const renderRoute = () =>
52
+ // if a Component is defined, render it using JSX syntax (<Component />)
53
+ // if not, check if a route.render function is defined and call that render function if available.
54
+ // if neither Component nor route.render is defined, return null
55
+ Component ? <Component /> : route.render ? route.render() : null;
56
+
28
57
  return (
29
58
  <Route
30
59
  key={route.path}
31
60
  path={route.path}
32
61
  element={
33
- <Suspense fallback={<Spinner />}>
34
- <Component />
35
- </Suspense>
62
+ <AuthGuard {...authProps}>
63
+ <Suspense fallback={<Spinner />}>{renderRoute()}</Suspense>
64
+ </AuthGuard>
36
65
  }
37
66
  />
38
67
  );
39
68
  })}
69
+ <Route path="*" element={<PageNotFound />} />
40
70
  </Routes>
41
71
  );
42
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lincd-cli",
3
- "version": "0.2.41",
3
+ "version": "0.2.42",
4
4
  "description": "Command line tools for the lincd.js library",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {