@poadio/starter-next 0.0.0-stage → 0.2.0

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.
Files changed (64) hide show
  1. package/.dockerignore +18 -0
  2. package/.env.example +8 -0
  3. package/Dockerfile +45 -0
  4. package/Dockerfile.dockerignore +18 -0
  5. package/README.md +197 -2
  6. package/bun.lock +156 -0
  7. package/gitignore +37 -0
  8. package/next.config.ts +14 -0
  9. package/package.json +72 -4
  10. package/public/logo.svg +1 -0
  11. package/public/providers/google.svg +1 -0
  12. package/public/providers/keycloak.svg +1 -0
  13. package/scripts/dev.mjs +92 -0
  14. package/scripts/env.mjs +160 -0
  15. package/scripts/env.test.mjs +93 -0
  16. package/src/app/(auth)/login/login-form.tsx +258 -0
  17. package/src/app/(auth)/login/page.tsx +16 -0
  18. package/src/app/(auth)/mfa/mfa-form.tsx +55 -0
  19. package/src/app/(auth)/mfa/page.tsx +16 -0
  20. package/src/app/(auth)/reset/page.tsx +16 -0
  21. package/src/app/(auth)/reset/reset-form.tsx +51 -0
  22. package/src/app/app/account/account.css +36 -0
  23. package/src/app/app/account/account.tsx +476 -0
  24. package/src/app/app/account/page.tsx +18 -0
  25. package/src/app/app/dashboard.tsx +58 -0
  26. package/src/app/app/hello/[name]/page.tsx +38 -0
  27. package/src/app/app/layout.tsx +12 -0
  28. package/src/app/app/page.tsx +18 -0
  29. package/src/app/app/public/page.tsx +15 -0
  30. package/src/app/app/public/public-content.tsx +31 -0
  31. package/src/app/globals.css +271 -0
  32. package/src/app/home.css +186 -0
  33. package/src/app/home.tsx +92 -0
  34. package/src/app/icon.svg +1 -0
  35. package/src/app/layout.tsx +59 -0
  36. package/src/app/not-found.tsx +6 -0
  37. package/src/app/page.tsx +6 -0
  38. package/src/app/providers.tsx +24 -0
  39. package/src/app/setup/page.tsx +39 -0
  40. package/src/app/shell.css +752 -0
  41. package/src/app.meta.ts +41 -0
  42. package/src/components/brand.tsx +15 -0
  43. package/src/components/captcha.tsx +93 -0
  44. package/src/components/link-button.tsx +9 -0
  45. package/src/components/rich.tsx +14 -0
  46. package/src/components/shell/app-menu.tsx +127 -0
  47. package/src/components/shell/app-shell.tsx +268 -0
  48. package/src/components/shell/page-title.tsx +29 -0
  49. package/src/components/shell/switches.tsx +35 -0
  50. package/src/components/shell/use-layout.ts +123 -0
  51. package/src/core/auth.tsx +228 -0
  52. package/src/core/env.server.ts +83 -0
  53. package/src/core/env.tsx +48 -0
  54. package/src/core/guards.tsx +74 -0
  55. package/src/core/messages.ts +18 -0
  56. package/src/core/providers.ts +32 -0
  57. package/src/core/theme-script.ts +7 -0
  58. package/src/core/theme.tsx +37 -0
  59. package/src/i18n/client.tsx +47 -0
  60. package/src/i18n/en.ts +228 -0
  61. package/src/i18n/fr.ts +251 -0
  62. package/src/i18n/index.ts +38 -0
  63. package/src/i18n/server.ts +19 -0
  64. package/tsconfig.json +21 -0
@@ -0,0 +1,92 @@
1
+ 'use client';
2
+ import Link from 'next/link';
3
+ import { PoadIcon } from '@poadio/ui-react';
4
+ import { APP } from '@/app.meta';
5
+ import { Brand } from '@/components/brand';
6
+ import { LocaleSwitch } from '@/components/shell/switches';
7
+ import { useAuth } from '@/core/auth';
8
+ import { useTheme } from '@/core/theme';
9
+ import { useT } from '@/i18n/client';
10
+ import './home.css';
11
+
12
+ /**
13
+ * Page de démarrage, hors du cadre de l'application. Écrite sur les tokens
14
+ * --poad-* : elle suit le thème clair/sombre. Les portes d'entrée disent où
15
+ * elles mènent et ce qu'elles démontrent ; à remplacer par celles de l'application.
16
+ */
17
+ export function Home() {
18
+ const theme = useTheme();
19
+ const auth = useAuth();
20
+ const t = useT();
21
+
22
+ const doors = [
23
+ auth.session
24
+ ? { icon: 'layout-dashboard', title: t('home.open'), text: t('home.openText', { name: auth.displayName }), link: '/app' }
25
+ : { icon: 'log-in', title: t('home.signIn'), text: t('home.signInText'), link: '/login' },
26
+ { icon: 'globe', title: t('home.public'), text: t('home.publicText'), link: '/app/public' },
27
+ { icon: 'book-open', title: t('home.docs'), text: t('home.docsText'), href: 'https://github.com/poadio' },
28
+ ];
29
+ const facts = [
30
+ { value: '1', label: t('home.fact1') },
31
+ { value: 'OAuth', label: t('home.fact2') },
32
+ { value: 'MFA', label: t('home.fact3') },
33
+ ];
34
+
35
+ return (
36
+ <div className="start">
37
+ <div className="start-grid" aria-hidden="true" />
38
+
39
+ <div className="start-tools">
40
+ <LocaleSwitch />
41
+ <button type="button" className="start-theme" aria-label={theme.dark ? t('common.toLight') : t('common.toDark')} onClick={theme.toggle}>
42
+ <PoadIcon name={theme.dark ? 'sun' : 'moon'} size={15} />
43
+ </button>
44
+ </div>
45
+
46
+ <main className="start-main">
47
+ <Brand className="start-brand" size={36} version />
48
+
49
+ <h1>
50
+ {t('home.title')}
51
+ <em>{t('home.titleAccent')}</em>
52
+ </h1>
53
+ <p className="start-lead">{t('home.lead', { description: APP.description })}</p>
54
+
55
+ <nav className="doors">
56
+ {doors.map((d) => {
57
+ const inner = (
58
+ <>
59
+ <span className="dicon">
60
+ <PoadIcon name={d.icon} size={17} />
61
+ </span>
62
+ <span className="dtxt">
63
+ <span className="dtitle">{d.title}</span>
64
+ <span className="dtext">{d.text}</span>
65
+ </span>
66
+ <PoadIcon className="darrow" name={d.href ? 'arrow-up-right' : 'arrow-right'} size={15} />
67
+ </>
68
+ );
69
+ return d.href ? (
70
+ <a key={d.title} className="door" href={d.href} target="_blank" rel="noopener">
71
+ {inner}
72
+ </a>
73
+ ) : (
74
+ <Link key={d.title} className="door" href={d.link!}>
75
+ {inner}
76
+ </Link>
77
+ );
78
+ })}
79
+ </nav>
80
+
81
+ <dl className="facts">
82
+ {facts.map((f) => (
83
+ <div key={f.label}>
84
+ <dt>{f.value}</dt>
85
+ <dd>{f.label}</dd>
86
+ </div>
87
+ ))}
88
+ </dl>
89
+ </main>
90
+ </div>
91
+ );
92
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="8" fill="#4f46e5"/><rect x="9.4" y="7" width="3.2" height="19" rx="1.6" fill="#fff"/><circle cx="17" cy="13" r="4.9" fill="none" stroke="#fff" stroke-width="3.2"/><circle cx="17" cy="13" r="1.5" fill="#fff"/></svg>
@@ -0,0 +1,59 @@
1
+ // Composants des pages : feuilles de @poadio/ui-core, une fois pour toute l'application
2
+ import '@poadio/ui-core/tokens.css';
3
+ import '@poadio/ui-core/base.css';
4
+ import '@poadio/ui-core/icon.css';
5
+ import '@poadio/ui-core/button.css';
6
+ import '@poadio/ui-core/field.css';
7
+ import '@poadio/ui-core/password.css';
8
+ import '@poadio/ui-core/meter.css';
9
+ import '@poadio/ui-core/select.css';
10
+ import '@poadio/ui-core/option-list.css';
11
+ import '@poadio/ui-core/floating.css';
12
+ import '@poadio/ui-core/sheet.css';
13
+ import '@poadio/ui-core/tooltip.css';
14
+ import '@poadio/ui-core/popover.css';
15
+ import '@poadio/ui-core/menu.css';
16
+ import '@poadio/ui-core/tabs.css';
17
+ import '@poadio/ui-core/tag.css';
18
+ import '@poadio/ui-core/message.css';
19
+ import '@poadio/ui-core/divider.css';
20
+ import '@poadio/ui-core/progress.css';
21
+ import '@poadio/ui-core/toast.css';
22
+ import '@poadio/ui-core/card.css';
23
+ import './globals.css';
24
+ import './shell.css';
25
+ import type { Metadata } from 'next';
26
+ import type { ReactNode } from 'react';
27
+ import { APP } from '@/app.meta';
28
+ import { publicEnv } from '@/core/env.server';
29
+ import { THEME_SCRIPT } from '@/core/theme-script';
30
+ import { getLocale } from '@/i18n/server';
31
+ import { Providers } from './providers';
32
+
33
+ export const metadata: Metadata = {
34
+ title: { default: APP.name, template: `%s · ${APP.name}` },
35
+ description: APP.description,
36
+ };
37
+
38
+ /**
39
+ * Racine, rendue par le serveur À CHAQUE REQUÊTE (la langue lit les cookies) :
40
+ * les variables publiques (POAD_URL, POAD_ANON_KEY, PUBLIC_*) sont lues dans
41
+ * l'environnement du serveur et dans le projet poad (variables de cette
42
+ * application) à ce moment-là, jamais compilées dans le code.
43
+ * L'image Docker est donc construite une fois et configurée au démarrage.
44
+ */
45
+ export default async function RootLayout({ children }: { children: ReactNode }) {
46
+ const locale = await getLocale();
47
+ return (
48
+ <html lang={locale} suppressHydrationWarning>
49
+ <head>
50
+ <script dangerouslySetInnerHTML={{ __html: THEME_SCRIPT }} />
51
+ </head>
52
+ <body>
53
+ <Providers env={await publicEnv()} locale={locale}>
54
+ {children}
55
+ </Providers>
56
+ </body>
57
+ </html>
58
+ );
59
+ }
@@ -0,0 +1,6 @@
1
+ import { redirect } from 'next/navigation';
2
+
3
+ /** Une URL inconnue ramène à l'accueil (comme le starter Angular) */
4
+ export default function NotFound() {
5
+ redirect('/');
6
+ }
@@ -0,0 +1,6 @@
1
+ import { Home } from './home';
2
+
3
+ /** Page de démarrage, hors du cadre de l'application (titre : celui de l'application) */
4
+ export default function HomePage() {
5
+ return <Home />;
6
+ }
@@ -0,0 +1,24 @@
1
+ 'use client';
2
+ import type { ReactNode } from 'react';
3
+ import { PoadToast } from '@poadio/ui-react';
4
+ import { AuthProvider } from '@/core/auth';
5
+ import { EnvProvider } from '@/core/env';
6
+ import { ThemeProvider } from '@/core/theme';
7
+ import { I18nProvider } from '@/i18n/client';
8
+ import type { Locale } from '@/i18n';
9
+
10
+ /** Fournisseurs de toute l'application : variables, langue, thème, session, toasts */
11
+ export function Providers({ env, locale, children }: { env: Record<string, string>; locale: Locale; children: ReactNode }) {
12
+ return (
13
+ <EnvProvider values={env}>
14
+ <I18nProvider locale={locale}>
15
+ <ThemeProvider>
16
+ <AuthProvider>
17
+ {children}
18
+ <PoadToast position="bottom-right" />
19
+ </AuthProvider>
20
+ </ThemeProvider>
21
+ </I18nProvider>
22
+ </EnvProvider>
23
+ );
24
+ }
@@ -0,0 +1,39 @@
1
+ import Link from 'next/link';
2
+ import { PoadCard, PoadMessage } from '@poadio/ui-react';
3
+ import { Brand } from '@/components/brand';
4
+ import { Rich } from '@/components/rich';
5
+ import { getT, titled } from '@/i18n/server';
6
+
7
+ export const generateMetadata = titled('title.setup');
8
+
9
+ const SAMPLE = 'docker run -p 8080:3000 \\\n -e POAD_URL=https://mon-projet.example.com \\\n -e POAD_ANON_KEY=eyJ… mon-app';
10
+
11
+ /** Affichée tant que POAD_URL et POAD_ANON_KEY manquent : comment brancher l'application sur poad */
12
+ export default async function SetupPage() {
13
+ const t = await getT();
14
+ return (
15
+ <div className="screen screen-top">
16
+ <section className="page setup" style={{ width: '100%', maxWidth: 620 }}>
17
+ <Link href="/" className="home-link">
18
+ <Brand size={32} />
19
+ </Link>
20
+ <h1>{t('setup.title')}</h1>
21
+ <PoadMessage severity="warning" variant="soft">
22
+ <Rich text={t('setup.missing')} />
23
+ </PoadMessage>
24
+ <PoadCard>
25
+ <ol>
26
+ <li>
27
+ <Rich text={t('setup.local')} />
28
+ </li>
29
+ <li>
30
+ <Rich text={t('setup.dotenv')} />
31
+ </li>
32
+ </ol>
33
+ <p className="muted">{t('setup.docker')}</p>
34
+ <pre className="json">{SAMPLE}</pre>
35
+ </PoadCard>
36
+ </section>
37
+ </div>
38
+ );
39
+ }