Compare commits

..

5 Commits

Author SHA1 Message Date
Amiram_se 9ea17684ad docs(decisions): record 0015–0019
0015 own route for a view with its own frame, 0016 needsProfile and OnboardingGuard, 0017 a loading skeleton per step (proposed); 0018 the /api rewrite and 0019 toasts close by themselves (accepted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 21:47:26 +04:00
Amiram_se cb0891c77c feat(market): complete entering and onboarding
Login, registration steps 1–4 and step 5 now follow the design (S6, R2-Register, R2-CompleteProfile).

- Login: hourly code limit and blocks open the code step with their wait; wrong-code message no longer replaced while retyping; suspended screen on its own route with the admin's reason; «log in to subscribe» variant.
- Registration: focus on the first card or empty upload box; typed number kept; «تمدید زمان» renews the token; live username check with ✓; leave prompt for in-app links; creator ID accepts PDF and maps server field errors.
- Step 5: square photo crop, stricter link rules, done screen on its own route; the session's `needsProfile` keeps unfinished creators out of publishing and pricing (OnboardingGuard) and sends them back to step 5 at login.
- Every auth and onboarding route has its own loading skeleton matching its frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 21:47:26 +04:00
Amiram_se ed6ddc05b1 feat(apps): call the API through a same-origin /api rewrite
- next.config rewrites /api/:path* to API_INTERNAL_ORIGIN, with a 120 s proxy timeout for uploads; NEXT_PUBLIC_API_ORIGIN is gone.
- The browser HTTP base is /api/v1; media, avatars and uploads load through /api (market env `apiBaseUrl`), so private media gets the session cookie.
- toApiUrl keeps a narrow rule for uploads stored with a host before the back end stored paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 21:47:18 +04:00
Amiram_se 0e8347d6d3 refactor(libs): share the origin env schema
`origin` (scheme and host only) lives in @lumina/libs/env, so the apps stop repeating it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 21:47:18 +04:00
Amiram_se 297f0b2cbd feat(island): focusable choice cards and file fields, state skeleton, timed toasts
- ChoiceCard and FileField forward a ref to their real input, so a form can move focus to the first empty card or upload box.
- SkeletonPreset gains a `state` preset (art, heading, line, action).
- Every toast closes by itself: errors after 8 s (10 with an action), others after 4 s (6 with an action).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 21:47:18 +04:00
203 changed files with 2753 additions and 761 deletions

View File

@ -1,13 +1,13 @@
# Copy to .env.local. Public variables are inlined into the browser bundle: never put a secret in one.
# The API's public origin; routes live under /v1, uploads under /files.
NEXT_PUBLIC_API_ORIGIN=http://localhost:3000
NEXT_PUBLIC_SITE_URL=http://localhost:3002
NEXT_PUBLIC_SITE_URL=http://localhost:7001
NEXT_PUBLIC_BALE_HANDLE=lumina_support
NEXT_PUBLIC_TELEGRAM_HANDLE=lumina_support
NEXT_PUBLIC_SUPPORT_HOURS=شنبه تا پنجشنبه، ۹ تا ۱۸
# Server only: the API origin from inside the deployment network.
# Server only: the gateway's origin from inside the deployment network. Server requests go
# there, and so does the browser's /api proxy (next.config rewrite, fixed at build time).
API_INTERNAL_ORIGIN=http://localhost:3000
# Only for steps that run without the real env (lint, type-check, image build).
# Only for steps that run without the real env (lint, type-check). A build still needs
# API_INTERNAL_ORIGIN: the /api rewrite keeps the value it was built with.
SKIP_ENV_VALIDATION=false

View File

@ -2,6 +2,9 @@ import { withFontCopy } from '@lumina/island/tools/font-copy-plugin';
import { withIconSprite } from '@lumina/island/tools/icon-sprite-plugin';
import type { NextConfig } from 'next';
import { API_PROXY_PATH, API_PROXY_TIMEOUT_MS } from './src/constants';
import { apiInternalUrl } from './src/env/env.config';
// Fonts and the icon sprite keep fixed names; a changed font gets a new name, and the sprite a new
// ?v= (0011, 0012). Next serves public/ with max-age=0, so without this every visit asks for them again.
const immutable = [
@ -9,6 +12,8 @@ const immutable = [
];
const nextConfig: NextConfig = {
// The `/api` proxy's wait for the gateway (0018); uploads outlast Next.js's 30-second default.
experimental: { proxyTimeout: API_PROXY_TIMEOUT_MS },
// Workspace packages export TypeScript source, so Next.js compiles them.
transpilePackages: [
'@lumina/market',
@ -20,8 +25,16 @@ const nextConfig: NextConfig = {
// `/@{username}` is the public channel URL. A folder named `@…` is a
// parallel-route slot in the App Router, so the routes live under
// `channels/[username]` and the public URL is rewritten onto them.
//
// The browser calls the API on this site's origin (`/api/v1/…`, `/api/files/…`), and the API
// calls are proxied to the gateway, so there is no CORS and the session cookies are this site's
// (0018).
async rewrites() {
return [
{
source: `${API_PROXY_PATH}/:path*`,
destination: `${apiInternalUrl()}/:path*`,
},
{
source: '/@:username/:path*',
destination: '/channels/:username/:path*',

View File

@ -0,0 +1,13 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Login, the number, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate>
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -3,8 +3,8 @@ import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
import { LoginStep } from '@lumina/market/app/screens/(auth)/auth/login/organisms/login-step';
import type { Metadata } from 'next';
import { i18n } from '../../../../i18n';
import { AuthTemplate } from '../../../templates/auth-template';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return { title: i18n.t('auth:login.meta-title'), robots: { index: false } };

View File

@ -0,0 +1,13 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
/** The suspended screen, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate width="wide">
<SkeletonPreset preset="state" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -0,0 +1,36 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
import { LoginSuspendedStep } from '@lumina/market/app/screens/(auth)/auth/login/suspended/organisms/login-suspended-step';
import type { Metadata } from 'next';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return {
title: i18n.t('auth:suspended.meta-title'),
robots: { index: false },
};
}
/**
* After a valid code for a suspended account (S6 3.1): the 560 card with the support button
* inside it. The frame renders on the server; the screen only in the browser (0013).
*/
export default function LoginSuspendedPage() {
return (
<AuthTemplate width="wide">
<GuestGuard
fallback={
<SkeletonPreset preset="state" label={i18n.t('auth:loading')} />
}
>
<LoginSuspendedStep
size="md"
supportPlacement="popover"
layout="desktop"
/>
</GuestGuard>
</AuthTemplate>
);
}

View File

@ -0,0 +1,13 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Login, the code, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate>
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -0,0 +1,18 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 1, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate width="wide">
<SkeletonPreset
preset="form"
count={2}
delayed
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -3,8 +3,8 @@ import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
import { RegisterTypeStep } from '@lumina/market/app/screens/(auth)/auth/register/organisms/register-type-step';
import type { Metadata } from 'next';
import { i18n } from '../../../../i18n';
import { AuthTemplate } from '../../../templates/auth-template';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return {

View File

@ -0,0 +1,18 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 4, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate width="wide">
<SkeletonPreset
preset="form"
count={3}
delayed
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -0,0 +1,18 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 2, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate>
<SkeletonPreset
preset="form"
count={1}
delayed
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -0,0 +1,18 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 3, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate>
<SkeletonPreset
preset="form"
count={1}
delayed
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -1,13 +0,0 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../i18n';
import { AuthTemplate } from '../templates/auth-template';
/** Login and registration, before their frame arrives: the header, the card and a form step's shape. */
export default function AuthLoading() {
return (
<AuthTemplate>
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -0,0 +1,2 @@
// Locked until a creator finishes registration step 5 (0016); the guard renders the page as is.
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';

View File

@ -0,0 +1,2 @@
// Locked until a creator finishes registration step 5 (0016); the guard renders the page as is.
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';

View File

@ -1,13 +0,0 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../i18n';
import { AuthTemplate } from '../templates/auth-template';
/** Registration's last steps, before their frame arrives: the header, the card and a form step's shape. */
export default function OnboardingLoading() {
return (
<AuthTemplate width="wide">
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -0,0 +1,16 @@
import { CreatorProfileStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/organisms/creator-profile-step';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 5 for a creator, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate framed={false}>
<CreatorProfileStepSkeleton
layout="desktop"
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -6,8 +6,8 @@ import {
import type { Metadata } from 'next';
import { Suspense } from 'react';
import { i18n } from '../../../../i18n';
import { AuthTemplate } from '../../../templates/auth-template';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return {

View File

@ -0,0 +1,13 @@
import { CreatorProfileDoneStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/done/organisms/creator-profile-done-step';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
/** The creator's end of registration, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate width="wide">
<CreatorProfileDoneStepSkeleton label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -0,0 +1,36 @@
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
import {
CreatorProfileDoneStep,
CreatorProfileDoneStepSkeleton,
} from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/done/organisms/creator-profile-done-step';
import type { Metadata } from 'next';
import { Suspense } from 'react';
import { i18n } from '../../../../../i18n';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return {
title: i18n.t('auth:register.profile.done.meta-title'),
robots: { index: false },
};
}
/**
* The end of registration for a creator (R2-CompleteProfile 3.3), in the 560 card. The frame renders on the server; the step only in the browser, for the signed-in creator,
* behind the same-size skeleton.
*/
export default function CreatorProfileDonePage() {
const skeleton = (
<CreatorProfileDoneStepSkeleton label={i18n.t('auth:loading')} />
);
return (
<AuthTemplate width="wide">
<AuthGuard role="creator" fallback={skeleton}>
<Suspense fallback={skeleton}>
<CreatorProfileDoneStep size="md" supportPlacement="popover" />
</Suspense>
</AuthGuard>
</AuthTemplate>
);
}

View File

@ -0,0 +1,13 @@
import { InvestorProfileStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
import { i18n } from '../../../../i18n';
import { AuthTemplate } from '../../../templates/auth-template';
/** Registration step 5 for an investor, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate width="wide">
<InvestorProfileStepSkeleton label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -1,6 +1,8 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
import { InvestorProfileStep } from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
import {
InvestorProfileStep,
InvestorProfileStepSkeleton,
} from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
import type { Metadata } from 'next';
import { i18n } from '../../../../i18n';
@ -23,11 +25,7 @@ export default function InvestorProfilePage() {
<AuthGuard
role="investor"
fallback={
<SkeletonPreset
preset="form"
count={2}
label={i18n.t('auth:loading')}
/>
<InvestorProfileStepSkeleton label={i18n.t('auth:loading')} />
}
>
<InvestorProfileStep size="md" supportPlacement="popover" />

View File

@ -5,22 +5,23 @@ import { mapApiErrorBody } from '@lumina/market/app/http';
import { setEnv as setMarketEnv } from '@lumina/market/env';
import { AUTH_ENDPOINTS, AUTH_EVENTS } from '@lumina/market/features/auth';
import { API_VERSION_PATH } from '../constants';
import { API_PROXY_PATH, API_VERSION_PATH } from '../constants';
import { clientEnv } from '../env';
import { ERROR_HANDLER_CONFIG } from './error-reporting';
// Fills the client module graph with public values only, before client components render (during
// SSR and in the browser). Idempotent: safe to run again.
setMarketEnv({
apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
apiBaseUrl: API_PROXY_PATH,
baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,
});
// The session lives in HttpOnly cookies the browser sends itself. A 401 runs one refresh for the
// whole app; when that fails the session is over and the shell signs the user out.
// The browser calls the API on this site's origin, proxied to the gateway (0018). The session
// lives in HttpOnly cookies the browser sends itself. A 401 runs one refresh for the whole app;
// when that fails the session is over and the shell signs the user out.
http.configure({
baseUrl: `${clientEnv.NEXT_PUBLIC_API_ORIGIN}${API_VERSION_PATH}`,
baseUrl: `${API_PROXY_PATH}${API_VERSION_PATH}`,
refresh: {
endpoint: AUTH_ENDPOINTS.refresh,
onFailure: () =>

View File

@ -7,14 +7,18 @@ import { mapApiErrorBody } from '@lumina/market/app/http';
import { setEnv as setMarketEnv } from '@lumina/market/env';
import { cookies } from 'next/headers';
import { API_VERSION_PATH, FORWARDED_COOKIES } from '../constants';
import {
API_PROXY_PATH,
API_VERSION_PATH,
FORWARDED_COOKIES,
} from '../constants';
import { clientEnv } from '../env';
import { serverEnv } from '../env/server';
import { ERROR_HANDLER_CONFIG } from './error-reporting';
// Fills the server module graph once, before rendering. Idempotent: safe to run again.
setMarketEnv({
apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
apiBaseUrl: API_PROXY_PATH,
baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,

View File

@ -1,2 +1,16 @@
/** Every gateway route except `/files/*` sits under this prefix. */
export const API_VERSION_PATH = '/v1';
/**
* Where the browser reaches the API: this site's own origin, under this path. next.config.ts
* rewrites it to the gateway (`API_INTERNAL_ORIGIN`), so no browser request is cross-origin and
* the session cookies belong to this site (0018). The server render calls the gateway directly.
*/
export const API_PROXY_PATH = '/api';
/**
* How long the `/api` proxy waits for the gateway. Next.js stops at 30 seconds by default; an
* upload (two 5 MB ID images, post media) on a slow connection takes longer, and the HTTP lib
* sets no timeout for uploads.
*/
export const API_PROXY_TIMEOUT_MS = 120_000;

View File

@ -1,2 +1,2 @@
export { API_VERSION_PATH } from './api';
export { API_PROXY_PATH, API_PROXY_TIMEOUT_MS, API_VERSION_PATH } from './api';
export { FORWARDED_COOKIES } from './cookies';

View File

@ -1,31 +1,19 @@
import { createClientEnv } from '@lumina/libs/env';
import * as v from 'valibot';
import { isOrigin } from './is-origin';
const required = v.pipe(v.string(), v.nonEmpty());
const url = v.pipe(v.string(), v.url());
/** Scheme and host only: request paths and media URLs are joined to it, so `https://api.lumina.ir/` would give `//v1`. */
const origin = v.pipe(
url,
v.check(
isOrigin,
'Must be an origin such as https://api.lumina.ir, with no path or trailing slash.',
),
);
/** Public variables, inlined into the browser bundle. Next.js inlines only literal reads. */
export const clientEnv = createClientEnv({
prefix: 'NEXT_PUBLIC_',
schema: {
NEXT_PUBLIC_API_ORIGIN: origin,
NEXT_PUBLIC_SITE_URL: url,
NEXT_PUBLIC_BALE_HANDLE: required,
NEXT_PUBLIC_TELEGRAM_HANDLE: required,
NEXT_PUBLIC_SUPPORT_HOURS: required,
},
runtimeEnv: {
NEXT_PUBLIC_API_ORIGIN: process.env.NEXT_PUBLIC_API_ORIGIN,
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL,
NEXT_PUBLIC_BALE_HANDLE: process.env.NEXT_PUBLIC_BALE_HANDLE,
NEXT_PUBLIC_TELEGRAM_HANDLE: process.env.NEXT_PUBLIC_TELEGRAM_HANDLE,

16
apps/bear/src/env/env.config.ts vendored Normal file
View File

@ -0,0 +1,16 @@
import { origin } from '@lumina/libs/env';
import * as v from 'valibot';
/**
* For next.config.ts only: the gateway the `/api` rewrite proxies to. No `server-only` here, as
* the config loads outside React. `next build` writes rewrites into its output, so the value is
* the one at build time (0018) and `SKIP_ENV_VALIDATION` can't skip it: a build without it fails
* here, rather than shipping a proxy to the wrong gateway.
*/
export function apiInternalUrl(): string {
const result = v.safeParse(origin, process.env.API_INTERNAL_ORIGIN);
if (result.success) return result.output;
throw new Error(
`API_INTERNAL_ORIGIN is needed to build: next.config rewrites /api to it and next build keeps the value (0018). ${result.issues[0].message}`,
);
}

View File

@ -1,22 +1,13 @@
import 'server-only';
import { origin } from '@lumina/libs/env';
import { createServerEnv } from '@lumina/libs/env/server';
import * as v from 'valibot';
import { isOrigin } from './is-origin';
/** Server variables; only server code imports them, through `env/server`. */
export const serverEnv = createServerEnv({
schema: {
// Scheme and host only, as NEXT_PUBLIC_API_ORIGIN: request paths are joined to it.
API_INTERNAL_ORIGIN: v.pipe(
v.string(),
v.url(),
v.check(
isOrigin,
'Must be an origin such as http://gateway:3000, with no path or trailing slash.',
),
),
/** The gateway from inside the deployment network: server requests and the `/api` proxy. */
API_INTERNAL_ORIGIN: origin,
},
runtimeEnv: process.env,
skipValidation: process.env.SKIP_ENV_VALIDATION === 'true',

View File

@ -1,8 +0,0 @@
/** `https://api.lumina.ir`, not `https://api.lumina.ir/` or `https://api.lumina.ir/v1`. */
export function isOrigin(value: string): boolean {
try {
return new URL(value).origin === value;
} catch {
return false;
}
}

View File

@ -1,13 +1,13 @@
# Copy to .env.local. Public variables are inlined into the browser bundle: never put a secret in one.
# The API's public origin; routes live under /v1, uploads under /files.
NEXT_PUBLIC_API_ORIGIN=http://localhost:3000
NEXT_PUBLIC_SITE_URL=http://localhost:3001
NEXT_PUBLIC_SITE_URL=http://localhost:7000
NEXT_PUBLIC_BALE_HANDLE=lumina_support
NEXT_PUBLIC_TELEGRAM_HANDLE=lumina_support
NEXT_PUBLIC_SUPPORT_HOURS=شنبه تا پنجشنبه، ۹ تا ۱۸
# Server only: the API origin from inside the deployment network.
# Server only: the gateway's origin from inside the deployment network. Server requests go
# there, and so does the browser's /api proxy (next.config rewrite, fixed at build time).
API_INTERNAL_ORIGIN=http://localhost:3000
# Only for steps that run without the real env (lint, type-check, image build).
# Only for steps that run without the real env (lint, type-check). A build still needs
# API_INTERNAL_ORIGIN: the /api rewrite keeps the value it was built with.
SKIP_ENV_VALIDATION=false

View File

@ -2,6 +2,9 @@ import { withFontCopy } from '@lumina/island/tools/font-copy-plugin';
import { withIconSprite } from '@lumina/island/tools/icon-sprite-plugin';
import type { NextConfig } from 'next';
import { API_PROXY_PATH, API_PROXY_TIMEOUT_MS } from './src/constants';
import { apiInternalUrl } from './src/env/env.config';
// Fonts and the icon sprite keep fixed names; a changed font gets a new name, and the sprite a new
// ?v= (0011, 0012). Next serves public/ with max-age=0, so without this every visit asks for them again.
const immutable = [
@ -9,6 +12,8 @@ const immutable = [
];
const nextConfig: NextConfig = {
// The `/api` proxy's wait for the gateway (0018); uploads outlast Next.js's 30-second default.
experimental: { proxyTimeout: API_PROXY_TIMEOUT_MS },
// Workspace packages export TypeScript source, so Next.js compiles them.
transpilePackages: [
'@lumina/market',
@ -20,8 +25,16 @@ const nextConfig: NextConfig = {
// `/@{username}` is the public channel URL. A folder named `@…` is a
// parallel-route slot in the App Router, so the routes live under
// `channels/[username]` and the public URL is rewritten onto them.
//
// The browser calls the API on this site's origin (`/api/v1/…`, `/api/files/…`), and the API
// calls are proxied to the gateway, so there is no CORS and the session cookies are this site's
// (0018).
async rewrites() {
return [
{
source: `${API_PROXY_PATH}/:path*`,
destination: `${apiInternalUrl()}/:path*`,
},
{
source: '/@:username/:path*',
destination: '/channels/:username/:path*',

View File

@ -0,0 +1,14 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Login, the number, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate header={<AuthTopBar />}>
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -3,9 +3,9 @@ import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
import { LoginStep } from '@lumina/market/app/screens/(auth)/auth/login/organisms/login-step';
import type { Metadata } from 'next';
import { i18n } from '../../../../i18n';
import { AuthTopBar } from '../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../templates/auth-template';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return { title: i18n.t('auth:login.meta-title'), robots: { index: false } };

View File

@ -0,0 +1,14 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
/** The suspended screen, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate header={<AuthTopBar />}>
<SkeletonPreset preset="state" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -0,0 +1,37 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
import { LoginSuspendedStep } from '@lumina/market/app/screens/(auth)/auth/login/suspended/organisms/login-suspended-step';
import type { Metadata } from 'next';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return {
title: i18n.t('auth:suspended.meta-title'),
robots: { index: false },
};
}
/**
* After a valid code for a suspended account (S6 1.11, 2.1): the brand header with support and
* no way back into login. The frame renders on the server; the screen only in the browser (0013).
*/
export default function LoginSuspendedPage() {
return (
<AuthTemplate header={<AuthTopBar />}>
<GuestGuard
fallback={
<SkeletonPreset preset="state" label={i18n.t('auth:loading')} />
}
>
<LoginSuspendedStep
size="lg"
supportPlacement="bottom"
layout="mobile"
/>
</GuestGuard>
</AuthTemplate>
);
}

View File

@ -0,0 +1,19 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { ROUTES } from '@lumina/market/app/navigation';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Login, the code, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate
header={
<AuthTopBar title={i18n.t('auth:login.header')} back={ROUTES.login} />
}
>
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -1,6 +1,6 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
import { ROUTES, withReturnPath } from '@lumina/market/app/navigation';
import { ROUTES } from '@lumina/market/app/navigation';
import { LoginVerifyStep } from '@lumina/market/app/screens/(auth)/auth/login/verify/organisms/login-verify-step';
import type { Metadata } from 'next';
@ -15,24 +15,12 @@ export function generateMetadata(): Metadata {
};
}
type LoginVerifyPageProps = {
searchParams: Promise<Record<string, string | string[] | undefined>>;
};
/** Login, the code. The frame renders on the server; the step only in the browser (0013). */
export default async function LoginVerifyPage({
searchParams,
}: LoginVerifyPageProps) {
const { redirect } = await searchParams;
const backHref = withReturnPath(
ROUTES.login,
typeof redirect === 'string' ? redirect : null,
);
export default function LoginVerifyPage() {
return (
<AuthTemplate
header={
<AuthTopBar title={i18n.t('auth:login.header')} backHref={backHref} />
<AuthTopBar title={i18n.t('auth:login.header')} back={ROUTES.login} />
}
>
<GuestGuard

View File

@ -0,0 +1,19 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 1, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate header={<AuthTopBar />}>
<SkeletonPreset
preset="form"
count={2}
delayed
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -3,9 +3,9 @@ import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
import { RegisterTypeStep } from '@lumina/market/app/screens/(auth)/auth/register/organisms/register-type-step';
import type { Metadata } from 'next';
import { i18n } from '../../../../i18n';
import { AuthTopBar } from '../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../templates/auth-template';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return {

View File

@ -0,0 +1,21 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 4, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate
header={<AuthTopBar title={i18n.t('auth:register.header')} />}
>
<SkeletonPreset
preset="form"
count={3}
delayed
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -0,0 +1,27 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { ROUTES } from '@lumina/market/app/navigation';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 2, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate
header={
<AuthTopBar
title={i18n.t('auth:register.header')}
back={ROUTES.register.type}
/>
}
>
<SkeletonPreset
preset="form"
count={1}
delayed
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -1,6 +1,6 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
import { ROUTES, withReturnPath } from '@lumina/market/app/navigation';
import { ROUTES } from '@lumina/market/app/navigation';
import { RegisterPhoneStep } from '@lumina/market/app/screens/(auth)/auth/register/phone/organisms/register-phone-step';
import type { Metadata } from 'next';
@ -15,26 +15,14 @@ export function generateMetadata(): Metadata {
};
}
type RegisterPhonePageProps = {
searchParams: Promise<Record<string, string | string[] | undefined>>;
};
/** Registration step 2, the number. The frame renders on the server; the step only in the browser (0013). */
export default async function RegisterPhonePage({
searchParams,
}: RegisterPhonePageProps) {
const { redirect } = await searchParams;
const backHref = withReturnPath(
ROUTES.register.type,
typeof redirect === 'string' ? redirect : null,
);
export default function RegisterPhonePage() {
return (
<AuthTemplate
header={
<AuthTopBar
title={i18n.t('auth:register.header')}
backHref={backHref}
back={ROUTES.register.type}
/>
}
>

View File

@ -0,0 +1,27 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { ROUTES } from '@lumina/market/app/navigation';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 3, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate
header={
<AuthTopBar
title={i18n.t('auth:register.header')}
back={ROUTES.register.phone}
/>
}
>
<SkeletonPreset
preset="form"
count={1}
delayed
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -1,6 +1,6 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { GuestGuard } from '@lumina/market/app/guards/guest-guard';
import { ROUTES, withReturnPath } from '@lumina/market/app/navigation';
import { ROUTES } from '@lumina/market/app/navigation';
import { RegisterVerifyStep } from '@lumina/market/app/screens/(auth)/auth/register/verify/organisms/register-verify-step';
import type { Metadata } from 'next';
@ -15,26 +15,14 @@ export function generateMetadata(): Metadata {
};
}
type RegisterVerifyPageProps = {
searchParams: Promise<Record<string, string | string[] | undefined>>;
};
/** Registration step 3, the code. The frame renders on the server; the step only in the browser (0013). */
export default async function RegisterVerifyPage({
searchParams,
}: RegisterVerifyPageProps) {
const { redirect } = await searchParams;
const backHref = withReturnPath(
ROUTES.register.phone,
typeof redirect === 'string' ? redirect : null,
);
export default function RegisterVerifyPage() {
return (
<AuthTemplate
header={
<AuthTopBar
title={i18n.t('auth:register.header')}
backHref={backHref}
back={ROUTES.register.phone}
/>
}
>

View File

@ -1,14 +0,0 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../i18n';
import { AuthTopBar } from '../organisms/auth-top-bar';
import { AuthTemplate } from '../templates/auth-template';
/** Login and registration, before their frame arrives: the top bar and a form step's shape. */
export default function AuthLoading() {
return (
<AuthTemplate header={<AuthTopBar />}>
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -0,0 +1,2 @@
// Locked until a creator finishes registration step 5 (0016); the guard renders the page as is.
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';

View File

@ -0,0 +1,2 @@
// Locked until a creator finishes registration step 5 (0016); the guard renders the page as is.
export { OnboardingGuard as default } from '@lumina/market/app/guards/onboarding-guard';

View File

@ -1,16 +0,0 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { i18n } from '../../i18n';
import { AuthTopBar } from '../organisms/auth-top-bar';
import { AuthTemplate } from '../templates/auth-template';
/** Registration's last steps, before their frame arrives: the top bar and a form step's shape. */
export default function OnboardingLoading() {
return (
<AuthTemplate
header={<AuthTopBar title={i18n.t('auth:register.header')} />}
>
<SkeletonPreset preset="form" delayed label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -0,0 +1,19 @@
import { CreatorProfileStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/organisms/creator-profile-step';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
/** Registration step 5 for a creator, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate
header={<AuthTopBar title={i18n.t('auth:register.header')} />}
>
<CreatorProfileStepSkeleton
layout="mobile"
label={i18n.t('auth:loading')}
/>
</AuthTemplate>
);
}

View File

@ -6,9 +6,9 @@ import {
import type { Metadata } from 'next';
import { Suspense } from 'react';
import { i18n } from '../../../../i18n';
import { AuthTopBar } from '../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../templates/auth-template';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return {

View File

@ -0,0 +1,14 @@
import { CreatorProfileDoneStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/done/organisms/creator-profile-done-step';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
/** The creator's end of registration, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate header={<AuthTopBar />}>
<CreatorProfileDoneStepSkeleton label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -0,0 +1,38 @@
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
import {
CreatorProfileDoneStep,
CreatorProfileDoneStepSkeleton,
} from '@lumina/market/app/screens/(onboarding)/onboarding/creator-profile/done/organisms/creator-profile-done-step';
import type { Metadata } from 'next';
import { Suspense } from 'react';
import { i18n } from '../../../../../i18n';
import { AuthTopBar } from '../../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../../templates/auth-template';
export function generateMetadata(): Metadata {
return {
title: i18n.t('auth:register.profile.done.meta-title'),
robots: { index: false },
};
}
/**
* The end of registration for a creator (R2-CompleteProfile 1.8): the brand header, as
* registration is over. The frame renders on the server; the step only in the browser, for the signed-in creator,
* behind the same-size skeleton.
*/
export default function CreatorProfileDonePage() {
const skeleton = (
<CreatorProfileDoneStepSkeleton label={i18n.t('auth:loading')} />
);
return (
<AuthTemplate header={<AuthTopBar />}>
<AuthGuard role="creator" fallback={skeleton}>
<Suspense fallback={skeleton}>
<CreatorProfileDoneStep size="lg" supportPlacement="bottom" />
</Suspense>
</AuthGuard>
</AuthTemplate>
);
}

View File

@ -0,0 +1,16 @@
import { InvestorProfileStepSkeleton } from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
import { i18n } from '../../../../i18n';
import { AuthTopBar } from '../../../organisms/auth-top-bar';
import { AuthTemplate } from '../../../templates/auth-template';
/** Registration step 5 for an investor, before its frame arrives. The same frame and skeleton as the page, so nothing moves when it arrives. */
export default function Loading() {
return (
<AuthTemplate
header={<AuthTopBar title={i18n.t('auth:register.header')} />}
>
<InvestorProfileStepSkeleton label={i18n.t('auth:loading')} />
</AuthTemplate>
);
}

View File

@ -1,6 +1,8 @@
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { AuthGuard } from '@lumina/market/app/guards/auth-guard';
import { InvestorProfileStep } from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
import {
InvestorProfileStep,
InvestorProfileStepSkeleton,
} from '@lumina/market/app/screens/(onboarding)/onboarding/investor-profile/organisms/investor-profile-step';
import type { Metadata } from 'next';
import { i18n } from '../../../../i18n';
@ -26,11 +28,7 @@ export default function InvestorProfilePage() {
<AuthGuard
role="investor"
fallback={
<SkeletonPreset
preset="form"
count={2}
label={i18n.t('auth:loading')}
/>
<InvestorProfileStepSkeleton label={i18n.t('auth:loading')} />
}
>
<InvestorProfileStep size="lg" supportPlacement="bottom" />

View File

@ -1,4 +1,3 @@
import { Button } from '@lumina/island/atoms/button';
import { FlexBox } from '@lumina/island/atoms/flex-box';
import { Typography } from '@lumina/island/atoms/typography';
import { ROUTES } from '@lumina/market/app/navigation';
@ -6,6 +5,7 @@ import { SupportEntry } from '@lumina/market/app/screens/organisms/support-entry
import NextLink from 'next/link';
import { i18n } from '../../../i18n';
import { BackButton } from './components/BackButton';
import type { AuthTopBarProps } from './types';
/**
@ -13,7 +13,7 @@ import type { AuthTopBarProps } from './types';
* support on a pushed step; only the name on a step with no way back (registration step 4).
* Back keeps what was typed: the number lives in the flow store.
*/
export function AuthTopBar({ title, backHref }: AuthTopBarProps) {
export function AuthTopBar({ title, back }: AuthTopBarProps) {
return (
<FlexBox
tag="header"
@ -21,19 +21,12 @@ export function AuthTopBar({ title, backHref }: AuthTopBarProps) {
gap="gap-1"
className="sticky top-0 z-sticky min-h-14 border-b border-border-subtle bg-surface px-2"
>
{backHref && (
<Button
variant="ghost"
icon="chevron-right"
label={i18n.t('auth:header.back')}
href={backHref}
/>
)}
{back && <BackButton step={back} label={i18n.t('auth:header.back')} />}
{title ? (
<Typography
tag="span"
variant="heading-sm"
className={backHref ? 'flex-1' : 'flex-1 px-2'}
className={back ? 'flex-1' : 'flex-1 px-2'}
>
{title}
</Typography>

View File

@ -0,0 +1,23 @@
'use client';
import { Button } from '@lumina/island/atoms/button';
import { withReturnPath } from '@lumina/market/app/navigation';
import { useSearchParams } from 'next/navigation';
import type { BackButtonProps } from '../types';
/**
* Back to the previous step, keeping `?redirect=` from the address bar, so a page and its loading
* frame lead to the same place and the person still returns to the page that asked for login.
*/
export function BackButton({ step, label }: BackButtonProps) {
const redirect = useSearchParams().get('redirect');
return (
<Button
variant="ghost"
icon="chevron-right"
label={label}
href={withReturnPath(step, redirect)}
/>
);
}

View File

@ -1,6 +1,11 @@
export type AuthTopBarProps = {
/** A pushed step's name, such as «ورود». Without it the bar shows the brand. */
title?: string;
/** The previous step, behind the back button. */
backHref?: string;
/** The previous step's path, behind the back button; `?redirect=` is kept from the address. */
back?: string;
};
export type BackButtonProps = {
step: string;
label: string;
};

View File

@ -5,22 +5,23 @@ import { mapApiErrorBody } from '@lumina/market/app/http';
import { setEnv as setMarketEnv } from '@lumina/market/env';
import { AUTH_ENDPOINTS, AUTH_EVENTS } from '@lumina/market/features/auth';
import { API_VERSION_PATH } from '../constants';
import { API_PROXY_PATH, API_VERSION_PATH } from '../constants';
import { clientEnv } from '../env';
import { ERROR_HANDLER_CONFIG } from './error-reporting';
// Fills the client module graph with public values only, before client components render (during
// SSR and in the browser). Idempotent: safe to run again.
setMarketEnv({
apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
apiBaseUrl: API_PROXY_PATH,
baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,
});
// The session lives in HttpOnly cookies the browser sends itself. A 401 runs one refresh for the
// whole app; when that fails the session is over and the shell signs the user out.
// The browser calls the API on this site's origin, proxied to the gateway (0018). The session
// lives in HttpOnly cookies the browser sends itself. A 401 runs one refresh for the whole app;
// when that fails the session is over and the shell signs the user out.
http.configure({
baseUrl: `${clientEnv.NEXT_PUBLIC_API_ORIGIN}${API_VERSION_PATH}`,
baseUrl: `${API_PROXY_PATH}${API_VERSION_PATH}`,
refresh: {
endpoint: AUTH_ENDPOINTS.refresh,
onFailure: () =>

View File

@ -7,14 +7,18 @@ import { mapApiErrorBody } from '@lumina/market/app/http';
import { setEnv as setMarketEnv } from '@lumina/market/env';
import { cookies } from 'next/headers';
import { API_VERSION_PATH, FORWARDED_COOKIES } from '../constants';
import {
API_PROXY_PATH,
API_VERSION_PATH,
FORWARDED_COOKIES,
} from '../constants';
import { clientEnv } from '../env';
import { serverEnv } from '../env/server';
import { ERROR_HANDLER_CONFIG } from './error-reporting';
// Fills the server module graph once, before rendering. Idempotent: safe to run again.
setMarketEnv({
apiOrigin: clientEnv.NEXT_PUBLIC_API_ORIGIN,
apiBaseUrl: API_PROXY_PATH,
baleHandle: clientEnv.NEXT_PUBLIC_BALE_HANDLE,
telegramHandle: clientEnv.NEXT_PUBLIC_TELEGRAM_HANDLE,
supportHours: clientEnv.NEXT_PUBLIC_SUPPORT_HOURS,

View File

@ -1,2 +1,16 @@
/** Every gateway route except `/files/*` sits under this prefix. */
export const API_VERSION_PATH = '/v1';
/**
* Where the browser reaches the API: this site's own origin, under this path. next.config.ts
* rewrites it to the gateway (`API_INTERNAL_ORIGIN`), so no browser request is cross-origin and
* the session cookies belong to this site (0018). The server render calls the gateway directly.
*/
export const API_PROXY_PATH = '/api';
/**
* How long the `/api` proxy waits for the gateway. Next.js stops at 30 seconds by default; an
* upload (two 5 MB ID images, post media) on a slow connection takes longer, and the HTTP lib
* sets no timeout for uploads.
*/
export const API_PROXY_TIMEOUT_MS = 120_000;

View File

@ -1,2 +1,2 @@
export { API_VERSION_PATH } from './api';
export { API_PROXY_PATH, API_PROXY_TIMEOUT_MS, API_VERSION_PATH } from './api';
export { FORWARDED_COOKIES } from './cookies';

View File

@ -1,31 +1,19 @@
import { createClientEnv } from '@lumina/libs/env';
import * as v from 'valibot';
import { isOrigin } from './is-origin';
const required = v.pipe(v.string(), v.nonEmpty());
const url = v.pipe(v.string(), v.url());
/** Scheme and host only: request paths and media URLs are joined to it, so `https://api.lumina.ir/` would give `//v1`. */
const origin = v.pipe(
url,
v.check(
isOrigin,
'Must be an origin such as https://api.lumina.ir, with no path or trailing slash.',
),
);
/** Public variables, inlined into the browser bundle. Next.js inlines only literal reads. */
export const clientEnv = createClientEnv({
prefix: 'NEXT_PUBLIC_',
schema: {
NEXT_PUBLIC_API_ORIGIN: origin,
NEXT_PUBLIC_SITE_URL: url,
NEXT_PUBLIC_BALE_HANDLE: required,
NEXT_PUBLIC_TELEGRAM_HANDLE: required,
NEXT_PUBLIC_SUPPORT_HOURS: required,
},
runtimeEnv: {
NEXT_PUBLIC_API_ORIGIN: process.env.NEXT_PUBLIC_API_ORIGIN,
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL,
NEXT_PUBLIC_BALE_HANDLE: process.env.NEXT_PUBLIC_BALE_HANDLE,
NEXT_PUBLIC_TELEGRAM_HANDLE: process.env.NEXT_PUBLIC_TELEGRAM_HANDLE,

16
apps/bull/src/env/env.config.ts vendored Normal file
View File

@ -0,0 +1,16 @@
import { origin } from '@lumina/libs/env';
import * as v from 'valibot';
/**
* For next.config.ts only: the gateway the `/api` rewrite proxies to. No `server-only` here, as
* the config loads outside React. `next build` writes rewrites into its output, so the value is
* the one at build time (0018) and `SKIP_ENV_VALIDATION` can't skip it: a build without it fails
* here, rather than shipping a proxy to the wrong gateway.
*/
export function apiInternalUrl(): string {
const result = v.safeParse(origin, process.env.API_INTERNAL_ORIGIN);
if (result.success) return result.output;
throw new Error(
`API_INTERNAL_ORIGIN is needed to build: next.config rewrites /api to it and next build keeps the value (0018). ${result.issues[0].message}`,
);
}

View File

@ -1,22 +1,13 @@
import 'server-only';
import { origin } from '@lumina/libs/env';
import { createServerEnv } from '@lumina/libs/env/server';
import * as v from 'valibot';
import { isOrigin } from './is-origin';
/** Server variables; only server code imports them, through `env/server`. */
export const serverEnv = createServerEnv({
schema: {
// Scheme and host only, as NEXT_PUBLIC_API_ORIGIN: request paths are joined to it.
API_INTERNAL_ORIGIN: v.pipe(
v.string(),
v.url(),
v.check(
isOrigin,
'Must be an origin such as http://gateway:3000, with no path or trailing slash.',
),
),
/** The gateway from inside the deployment network: server requests and the `/api` proxy. */
API_INTERNAL_ORIGIN: origin,
},
runtimeEnv: process.env,
skipValidation: process.env.SKIP_ENV_VALIDATION === 'true',

View File

@ -1,8 +0,0 @@
/** `https://api.lumina.ir`, not `https://api.lumina.ir/` or `https://api.lumina.ir/v1`. */
export function isOrigin(value: string): boolean {
try {
return new URL(value).origin === value;
} catch {
return false;
}
}

View File

@ -0,0 +1,16 @@
# 0015 A view with its own frame gets its own route
Status: Proposed · Area: architecture · Date: 2026-10-06 · Decided by: agent
## Context
The suspended screen (S6 1.11, 2.1, 3.1) and the creator's end of registration (R2-CompleteProfile 1.8, 3.3) show a different header or card width than the step they follow. The frame renders on the server and can't know a browser-only state, so a view swap inside the step kept the wrong header and card.
## Decision
- When a login, registration or onboarding view needs a different frame than its step, serve it on its own route: `/auth/login/suspended`, `/onboarding/creator-profile/done`. The step sends the person there with `router.replace`.
- What the view needs and the server can't give stays in memory (the flow store); a reload without it falls back to the step's start, as other flow steps do (0013). A view that can read its data from the API (the end of registration) reads it, so it survives a reload.
## Alternatives
- A client header that reads a store: rejected; the server frame and the skeleton would still differ from the view.
## Consequences
- Each such view has its own page, loading skeleton and metadata in both apps.

View File

@ -0,0 +1,18 @@
# 0016 Unfinished creators stay on step 5, from the session
Status: Proposed · Area: architecture · Date: 2026-10-06 · Decided by: agent
## Context
R2-CompleteProfile 4.2: a creator's channel, publishing and prices stay unavailable until step 5 is done, and the next login opens step 5 again. Before, only a fresh login knew, through its own profile read.
## Decision
- The API's session answers (login, session, refresh, registration) carry `needsProfile`, and the auth store keeps it; `completeCreatorProfile`, and step 5 or its end finding the profile complete, clear it.
- `OnboardingGuard`, rendered by the layouts of the locked routes (`compose`, `dashboard/pricing`), sends such a creator to step 5 with the current page as `?redirect=`; `GuestGuard` does the same on the auth pages. Neither changes the server render. Every other page, such as the terms, stays open.
- Step 5 sends a creator whose profile is already complete on to `?redirect=`, else their channel. The channel itself stays hidden by the back end (unapproved creators answer 404).
## Alternatives
- Read the profile in the browser after each session read: rejected; an extra serial request per page load, and a failed read let the creator in.
- Guard every page outside onboarding: rejected; it locked pages the design keeps open, such as the terms linked from step 5's support.
## Consequences
- The trader service answers one more call per creator session read; a failed call counts as not done. The back end still enforces the lock on posting and tiers (0014).

View File

@ -0,0 +1,16 @@
# 0017 Each step owns its loading skeleton
Status: Proposed · Area: architecture · Date: 2026-10-06 · Decided by: agent
## Context
A route group's `loading.tsx` showed one frame for every step under it, so navigating to a step with another header or card width moved the page when it arrived. Next.js also shows the loading of the first new segment, so a parent step's `loading.tsx` covers its nested steps.
## Decision
- Every login, registration and onboarding route has its own `loading.tsx` with its page's frame and fallback skeleton; the route groups have none.
- A route whose page has nested steps puts its page and loading in a route group of its own: `login/(number)`, `register/(type)`, `creator-profile/(form)`.
## Alternatives
- One loading per group: rejected; its frame matches only some steps.
## Consequences
- Page and loading repeat the frame; change them together.

View File

@ -0,0 +1,21 @@
# 0018 The browser calls the API through a Next.js rewrite
Status: Accepted · Area: architecture · Date: 2026-10-06 · Decided by: user
## Context
The browser called the gateway on its own origin with credentials, so every call was cross-origin: CORS preflights, a CORS allowlist to keep in step, and session cookies that belonged to the API host.
## Decision
- The browser calls the API on the app's own origin (bull :7000, bear :7001) under `/api` (`API_PROXY_PATH`): `/api/v1/…` and `/api/files/…`. Each app's `next.config.ts` rewrites `/api/:path*` to `${apiInternalUrl()}/:path*`, the gateway's `API_INTERNAL_ORIGIN`.
- Media and avatar URLs from the API go through the same path (`toApiUrl`, market env `apiBaseUrl`), so private media gets the session cookie.
- The server render still calls the gateway directly at `API_INTERNAL_ORIGIN` and still sends no session cookies.
- The gateway scopes the refresh cookie to `/api/v1/auth` (`AUTH_COOKIE_PATH_PREFIX=/api`), and keeps the apps' origins in `CORS_ORIGINS` for its origin check.
## Alternatives
- Direct cross-origin calls with CORS: the previous setup, replaced.
- A route handler proxy reading the origin at run time: not chosen; the rewrite is simpler.
## Consequences
- No `NEXT_PUBLIC_API_ORIGIN`. `next build` fixes the rewrite's destination at build time, so each environment's build needs its own `API_INTERNAL_ORIGIN`; `SKIP_ENV_VALIDATION` can't skip it, and a build without it fails.
- API traffic, uploads included, passes through the Next.js server. Its proxy waits `API_PROXY_TIMEOUT_MS` (120 s, `experimental.proxyTimeout`) instead of Next.js's 30 s.
- The proxy adds only `X-Forwarded-Host` and passes the browser's `X-Forwarded-For` on as sent; Next.js can't see the client's address. The client IP must come from the edge in front of the apps (it sets `X-Forwarded-For`), with the gateway trusting that chain (back end: 02-architecture, 08-devops). Without such an edge, the forwarded IP is the client's own claim.

View File

@ -0,0 +1,17 @@
# 0019 Every toast closes by itself
Status: Accepted · Area: design · Date: 2026-10-06 · Decided by: user
## Context
Action-error toasts stayed until dismissed (`duration: Infinity`), so one could follow the person to the next pages and never leave. The user asked for every toast to disappear after a delay.
## Decision
- Every toast closes on its own: success and info after 4 seconds (6 with an action), errors after 8 seconds (10 with their «تلاش دوباره» or reload button).
- Island's `showToast` sets these defaults by tone; callers pass `duration` only for a reason they can name, never `Infinity`.
- Hovering or focusing a toast, or leaving the tab, pauses its clock (sonner 2 does this itself).
## Alternatives
- Errors stay until dismissed: the skill's default; replaced at the user's request.
## Consequences
- What an error asks the person to do must also show on the page (a field error, the form alert or the state), not only in the toast, as the form rules already require.

View File

@ -4,12 +4,14 @@
- 0002 Render every tag through island `Element`, flex layouts through `FlexBox`, grid layouts through `GridBox`; never native JSX tags or `flex`/`grid` classes, island included.
- 0011 Serve Yekan Bakh FaNum (`font-sans`, all UI text) and Yekan Bakh (`font-latin`, شبا and bank codes only) from `public/fonts/` under fixed names declared in island `fonts.css`; no version, never hashed, never `next/font`; a changed font gets a new name.
- 0019 Close every toast by itself: success and info after 4 s (6 with an action), errors after 8 s (10 with an action); hovering or a hidden tab pauses it; never `duration: Infinity`.
## Architecture (ADR)
- 0001 Share one platform, `platforms/market`, between `apps/bull` and `apps/bear`; tag all three `scope:market`.
- 0012 Wrap each app's `next.config` in island's `withIconSprite` and `withFontCopy`; they write `symbol-defs.svg` and the fonts into `public/` unhashed, served immutable; link the sprite as `?v=<ICON_SPRITE_VERSION>`.
- 0013 Render every `(auth)` page's steps only in the browser behind `GuestGuard`: the server sends the frame, a same-size skeleton and `noindex`; flow state stays in memory, never in the URL or storage.
- 0018 Call the API from the browser only on the app's own origin under `/api`, rewritten by `next.config.ts` to `API_INTERNAL_ORIGIN`; media URLs use the same path, and the server render calls the gateway directly.
## Proposed
@ -17,3 +19,6 @@
- 0005 design: Island holds Lumina's product components and status-to-tone map; they take every text as props (`children` or `labels`) and never import i18next or platform code.
- 0006 architecture: Make every non-app project a pnpm workspace package `@lumina/<name>` with subpath `exports`; third-party dependencies stay in the root package.json.
- 0014 architecture: Serve registration step 5 under `(onboarding)` behind `AuthGuard`; a creator's profile autosaves as a server draft (`PATCH`) and completes only through `POST …/profile/complete`.
- 0015 architecture: Serve a login or onboarding view whose frame differs from its step on its own route (`/auth/login/suspended`, `/onboarding/creator-profile/done`); browser-only data stays in memory.
- 0016 architecture: Keep a creator who hasn't finished step 5 out of publishing and pricing through the session's `needsProfile`, with `OnboardingGuard` in those routes' layouts and `GuestGuard`.
- 0017 architecture: Give every auth and onboarding route its own `loading.tsx` matching its frame; an index route with nested steps sits in its own route group.

View File

@ -24,6 +24,7 @@ export function ChoiceCard({
checked = false,
multiple = false,
onChange,
ref,
title,
description,
icon,
@ -41,6 +42,7 @@ export function ChoiceCard({
>
<Element
tag="input"
ref={ref}
type={multiple ? 'checkbox' : 'radio'}
name={name}
value={value}

View File

@ -1,4 +1,4 @@
import type { ChangeEvent, ReactNode } from 'react';
import type { ChangeEvent, ReactNode, Ref } from 'react';
import type { IconName } from '../../atoms/icon';
@ -9,6 +9,8 @@ export type ChoiceCardProps = {
/** A checkbox instead of a radio, for a many-of choice. */
multiple?: boolean;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
/** The real radio, so a form can move focus to the first card when nothing was chosen. */
ref?: Ref<HTMLInputElement>;
title: ReactNode;
description?: ReactNode;
/** `investor` and `analyst` for the account type. */

View File

@ -24,6 +24,7 @@ export function FileField({
size,
onChange,
onBlur,
ref,
accept,
error,
progress,
@ -130,6 +131,7 @@ export function FileField({
</Typography>
<Element
tag="input"
ref={ref}
type="file"
id={id}
name={name}

View File

@ -1,4 +1,4 @@
import type { ReactNode } from 'react';
import type { ReactNode, Ref } from 'react';
/** Every text the field shows, from the translations. */
export type FileFieldLabels = {
@ -22,6 +22,8 @@ export type FileFieldProps = {
/** A picked file, or `null` when removed. Check type and size here, when it is picked. */
onChange: (file: File | null) => void;
onBlur?: () => void;
/** The picker input, so a form can move focus to an empty required box. */
ref?: Ref<HTMLInputElement>;
/** MIME types for the picker, such as `image/jpeg,image/png`. */
accept?: string;
/** Inline error under the box; a rejected file leaves the box empty. */

View File

@ -7,6 +7,13 @@ export const TOAST_ICONS: Record<ToastTone, IconName> = {
error: 'alert',
};
/** About 4 seconds to read one line; 6 when there is an action to reach. */
/**
* Every toast closes by itself (0019); sonner pauses the clock while it is hovered or focused, or
* the tab is hidden. About 4
* seconds to read one line, 6 when there is an action to reach. An error says what failed, why
* and what to do, so it stays 8 seconds, 10 with its action.
*/
export const TOAST_DURATION_MS = 4000;
export const TOAST_WITH_ACTION_DURATION_MS = 6000;
export const TOAST_ERROR_DURATION_MS = 8000;
export const TOAST_ERROR_WITH_ACTION_DURATION_MS = 10000;

View File

@ -1,12 +1,31 @@
import { toast } from 'sonner';
import { TOAST_DURATION_MS, TOAST_WITH_ACTION_DURATION_MS } from './constants';
import {
TOAST_DURATION_MS,
TOAST_ERROR_DURATION_MS,
TOAST_ERROR_WITH_ACTION_DURATION_MS,
TOAST_WITH_ACTION_DURATION_MS,
} from './constants';
import { Toast } from './Toast';
import type { ShowToastOptions } from './types';
/** How long a toast stays when the caller doesn't say: longer for an error, longer with an action. */
function defaultDuration(
tone: ShowToastOptions['tone'],
hasAction: boolean,
): number {
if (tone === 'error') {
return hasAction
? TOAST_ERROR_WITH_ACTION_DURATION_MS
: TOAST_ERROR_DURATION_MS;
}
return hasAction ? TOAST_WITH_ACTION_DURATION_MS : TOAST_DURATION_MS;
}
/**
* Shows a toast after an action completes or fails; never for a read. Tapping the action also
* closes the toast. Returns the toast's id for `dismissToast`.
* Shows a toast after an action completes or fails; never for a read. Every toast closes by
* itself (0019). Tapping the action also closes the toast. Returns the toast's id for
* `dismissToast`.
*/
export function showToast({
id,
@ -36,9 +55,7 @@ export function showToast({
),
{
id,
duration:
duration ??
(action ? TOAST_WITH_ACTION_DURATION_MS : TOAST_DURATION_MS),
duration: duration ?? defaultDuration(props.tone, Boolean(action)),
},
);
}

View File

@ -36,7 +36,7 @@ export type ShowToastOptions = Omit<
message: ReactNode;
/** A toast shown again under the same id replaces the old one instead of stacking. */
id?: string;
/** Defaults to 4 seconds, 6 with an action. */
/** Defaults to 4 seconds (6 with an action); an error to 8 (10 with an action). */
duration?: number;
};

View File

@ -5,6 +5,7 @@ import { HeaderSkeleton } from './components/HeaderSkeleton';
import { ListSkeleton } from './components/ListSkeleton';
import { PostSkeleton } from './components/PostSkeleton';
import { PredictionSkeleton } from './components/PredictionSkeleton';
import { StateSkeleton } from './components/StateSkeleton';
import { StatsSkeleton } from './components/StatsSkeleton';
import { TableSkeleton } from './components/TableSkeleton';
import { DEFAULT_TABLE_COLUMNS, PRESET_REPEATS } from './constants';
@ -46,6 +47,7 @@ export function SkeletonPreset({
{preset === 'list' && <ListSkeleton rows={n} avatar={avatar} />}
{preset === 'table' && <TableSkeleton rows={n} columns={columns} />}
{preset === 'form' && <FormSkeleton fields={n} />}
{preset === 'state' && <StateSkeleton />}
</SkeletonRegion>
);
}

View File

@ -0,0 +1,30 @@
import { FlexBox } from '../../../atoms/flex-box';
import { Skeleton } from '../../../atoms/skeleton';
/**
* A full-page state, such as a suspended account: the 104px art, the heading, one line of text and
* the full-width action under them, centred. No card: it fills whatever frame the screen draws.
*/
export function StateSkeleton() {
return (
<FlexBox
direction="flex-col"
alignItems="items-center"
gap="gap-4"
className="pt-6"
aria-hidden
>
<Skeleton shape="circle" className="size-26" />
<FlexBox
direction="flex-col"
alignItems="items-center"
gap="gap-2"
className="w-full"
>
<Skeleton className="h-6 w-[55%]" />
<Skeleton className="w-[75%]" />
</FlexBox>
<Skeleton shape="pill" className="mt-2 h-control-lg w-full" />
</FlexBox>
);
}

View File

@ -19,7 +19,9 @@ export type SkeletonPresetName =
/** A money hero («قابل واریز») with two tiles under it. */
| 'figure'
/** A form step: heading, description, `count` fields, the submit button and a link. */
| 'form';
| 'form'
/** A full-page state: the art, heading, one line and the action (a suspended account). */
| 'state';
export type SkeletonPresetProps = {
/** The component the screen is waiting for. */

View File

@ -1,4 +1,5 @@
export { createClientEnv } from './env.client';
export { origin } from './schemas';
export type {
ClientEnvOptions,
EnvSchema,

23
packages/libs/src/env/schemas.ts vendored Normal file
View File

@ -0,0 +1,23 @@
import * as v from 'valibot';
/** `https://api.lumina.ir`, not `https://api.lumina.ir/` or `https://api.lumina.ir/v1`. */
function isOrigin(value: string): boolean {
try {
return new URL(value).origin === value;
} catch {
return false;
}
}
/**
* A scheme and host only, such as `http://gateway:3000`: paths are joined to it, so a trailing
* slash or a path would give `//v1` or `/v1/v1`.
*/
export const origin = v.pipe(
v.string(),
v.url(),
v.check(
isOrigin,
'Must be an origin such as https://api.example.com, with no path or trailing slash.',
),
);

View File

@ -3,18 +3,20 @@
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import { useViewerStatus } from '../../../stores/auth';
import { safeReturnPath } from '../../navigation';
import { useNeedsProfile, useViewerStatus } from '../../../stores/auth';
import { ROUTES, safeReturnPath, withReturnPath } from '../../navigation';
import type { GuestGuardProps } from './types';
/**
* Wraps login and registration, which render only in the browser. A visitor who arrives signed in
* goes on to `?redirect=` (a path on this site only) or home; a guest sees the page. The skeleton
* goes on to `?redirect=` (a path on this site only) or home, or to registration step 5 when they
* are a creator who has not finished it; a guest sees the page. The skeleton
* covers the moment before the viewer is known. A guest who signs in on the page keeps it: the
* page shows its progress and sends them on itself.
*/
export function GuestGuard({ fallback, children }: GuestGuardProps) {
const status = useViewerStatus();
const needsProfile = useNeedsProfile();
const router = useRouter();
const [wasGuest, setWasGuest] = useState(false);
// Remembered during render, so the render that turns member already knows.
@ -25,8 +27,12 @@ export function GuestGuard({ fallback, children }: GuestGuardProps) {
const redirect = new URLSearchParams(window.location.search).get(
'redirect',
);
router.replace(safeReturnPath(redirect));
}, [status, wasGuest, router]);
router.replace(
needsProfile
? withReturnPath(ROUTES.onboarding.creatorProfile, redirect)
: safeReturnPath(redirect),
);
}, [status, needsProfile, wasGuest, router]);
const showsPage = status === 'guest' || (status === 'member' && wasGuest);
return showsPage ? children : fallback;

View File

@ -0,0 +1,31 @@
'use client';
import { useRouter } from 'next/navigation';
import { useEffect } from 'react';
import { useNeedsProfile, useViewerStatus } from '../../../stores/auth';
import { ROUTES, withReturnPath } from '../../navigation';
import type { OnboardingGuardProps } from './types';
/**
* Keeps a creator who has not finished registration step 5 away from what stays locked until
* then: publishing and prices (R2-CompleteProfile 4.2). It changes nothing in the render, so the
* server HTML stays the same for every visitor; once the browser knows the viewer, such a creator
* goes to step 5, which returns here when done. The layouts of those routes render it
* (`compose`, `dashboard/pricing`); everything else, such as the terms, stays open.
*/
export function OnboardingGuard({ children }: OnboardingGuardProps) {
const status = useViewerStatus();
const needsProfile = useNeedsProfile();
const router = useRouter();
useEffect(() => {
if (status !== 'member' || !needsProfile) return;
const { pathname, search } = window.location;
router.replace(
withReturnPath(ROUTES.onboarding.creatorProfile, `${pathname}${search}`),
);
}, [status, needsProfile, router]);
return children;
}

View File

@ -0,0 +1,2 @@
export { OnboardingGuard } from './OnboardingGuard';
export type { OnboardingGuardProps } from './types';

View File

@ -0,0 +1,3 @@
import type { ReactNode } from 'react';
export type OnboardingGuardProps = { children: ReactNode };

View File

@ -1,2 +1,5 @@
/** The public channel URL prefix; next.config rewrites `/@username` onto `channels/[username]`. */
export const CHANNEL_PREFIX = '/@';
/** Login's query parameter naming the channel a guest wants to subscribe to. */
export const SUBSCRIBE_PARAM = 'subscribe';

View File

@ -1,23 +1,44 @@
import { useSearchParams } from 'next/navigation';
import { useMemo } from 'react';
import * as v from 'valibot';
import type { SignedInViewer } from '../../../features/auth';
import { usernameSchema } from '../../../shared/validations';
import { SUBSCRIBE_PARAM } from '../constants';
import { ROUTES, withReturnPath } from '../navigation';
import { safeReturnPath } from '../return-path';
import type { AuthRoutes } from '../types';
/**
* The channel named by `?subscribe=`, as the API stores it, only when the person returns to that
* same channel (`?redirect=`): the notice says where they go back to, so any other pair, or a
* name that is no username, shows the plain login.
*/
function toSubscribeUsername(
subscribe: string | null,
redirect: string | null,
): string | null {
const parsed = v.safeParse(usernameSchema, subscribe ?? '');
return parsed.success && redirect === ROUTES.channel(parsed.output)
? parsed.output
: null;
}
/**
* Every login and registration step's path, each keeping `?redirect=`, and where a person lands
* once signed in. Browser only: the auth pages render their steps in the browser.
*/
export function useAuthRoutes(): AuthRoutes {
const redirect = useSearchParams().get('redirect');
const params = useSearchParams();
const redirect = params.get('redirect');
const subscribe = params.get(SUBSCRIBE_PARAM);
return useMemo(() => {
const step = (path: string) => withReturnPath(path, redirect);
return {
login: step(ROUTES.login),
loginVerify: step(ROUTES.loginVerify),
loginSuspended: ROUTES.loginSuspended,
register: {
type: step(ROUTES.register.type),
phone: step(ROUTES.register.phone),
@ -27,12 +48,14 @@ export function useAuthRoutes(): AuthRoutes {
profile: {
investor: step(ROUTES.onboarding.investorProfile),
creator: step(ROUTES.onboarding.creatorProfile),
creatorDone: step(ROUTES.onboarding.creatorProfileDone),
},
landing: ({ role, username, needsProfile }: SignedInViewer) => {
if (needsProfile) return step(ROUTES.onboarding.creatorProfile);
if (redirect) return safeReturnPath(redirect);
return role === 'creator' ? ROUTES.channel(username) : ROUTES.home;
},
subscribeTo: toSubscribeUsername(subscribe, redirect),
};
}, [redirect]);
}, [redirect, subscribe]);
}

View File

@ -1,5 +1,10 @@
export { CHANNEL_PREFIX } from './constants';
export { useAuthRoutes } from './hooks/use-auth-routes';
export { loginRoute, ROUTES, withReturnPath } from './navigation';
export {
loginRoute,
ROUTES,
subscribeLoginRoute,
withReturnPath,
} from './navigation';
export { safeReturnPath } from './return-path';
export type { AuthRoutes } from './types';

View File

@ -1,4 +1,4 @@
import { CHANNEL_PREFIX } from './constants';
import { CHANNEL_PREFIX, SUBSCRIBE_PARAM } from './constants';
const channel = (username: string) =>
`${CHANNEL_PREFIX}${encodeURIComponent(username)}`;
@ -8,6 +8,8 @@ export const ROUTES = {
home: '/',
login: '/auth/login',
loginVerify: '/auth/login/verify',
/** After a valid code for a suspended account: no session, only support. */
loginSuspended: '/auth/login/suspended',
register: {
type: '/auth/register',
phone: '/auth/register/phone',
@ -32,8 +34,9 @@ export const ROUTES = {
sheba: '/dashboard/finance/sheba',
},
onboarding: {
creatorIdentity: '/onboarding/creator-identity',
creatorProfile: '/onboarding/creator-profile',
/** The end of registration for a creator: what happens next. */
creatorProfileDone: '/onboarding/creator-profile/done',
investorProfile: '/onboarding/investor-profile',
},
terms: '/terms/subscription',
@ -44,6 +47,15 @@ export function loginRoute(returnTo?: string): string {
return withReturnPath(ROUTES.login, returnTo);
}
/**
* Login for a guest who tapped «اشتراک» on a channel: the login page says why, and the person
* comes back to the channel (S6 Login · to-subscribe). The channel page's «اشتراک» links here;
* until that page is built (the channel epic), nothing does.
*/
export function subscribeLoginRoute(username: string): string {
return `${loginRoute(channel(username))}&${SUBSCRIBE_PARAM}=${encodeURIComponent(username)}`;
}
/**
* An auth step's path that keeps `?redirect=`, so every step of login and registration returns
* to the page that asked for it.

View File

@ -4,13 +4,16 @@ import type { SignedInViewer } from '../../features/auth';
export type AuthRoutes = {
login: string;
loginVerify: string;
loginSuspended: string;
register: {
type: string;
phone: string;
verify: string;
details: string;
};
/** Registration step 5, per account type. */
profile: { investor: string; creator: string };
/** Registration step 5, per account type, and the creator's end of registration. */
profile: { investor: string; creator: string; creatorDone: string };
landing: (viewer: SignedInViewer) => string;
/** The channel's username when a guest came to log in from «اشتراک», else `null`. */
subscribeTo: string | null;
};

View File

@ -18,7 +18,8 @@ import type { LoginStepProps } from './types';
/**
* Login step 1: the mobile number and «دریافت کد» right under it, the way to registration, and
* support. A number with no account gets the way to register with it under the field.
* support. A number with no account gets the way to register with it under the field. A guest
* who came from «اشتراک» reads why, and which channel they return to (S6 Login · to-subscribe).
*/
export function LoginStep({ size, supportPlacement }: LoginStepProps) {
const { t } = useTranslation('auth');
@ -28,26 +29,31 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
submit,
isSubmitting,
formError,
clearError,
isUnknownPhone,
registerHref,
carryPhone,
subscribe,
} = useLoginPage({
codeHref: routes.loginVerify,
registerHref: routes.register.type,
subscribeTo: routes.subscribeTo,
});
return (
<FlexBox direction="flex-col" gap="gap-6" className="flex-1">
{/* The toast carries the details; the banner says what to do (S6 1.5). */}
{formError && (
<Banner tone="danger" title={t('phone.send-failed-banner')}>
{formError}
</Banner>
<Banner tone="danger">{t('phone.send-failed-banner')}</Banner>
)}
<FlexBox direction="flex-col" className="gap-1.5">
<Typography tag="h1" variant="heading-md">
{t('login.title')}
{subscribe ? t('login.subscribe.title') : t('login.title')}
</Typography>
<Typography color="secondary">
{subscribe
? t('login.subscribe.return', { name: subscribe.channelName })
: t('login.description')}
</Typography>
<Typography color="secondary">{t('login.description')}</Typography>
</FlexBox>
<FlexBox
tag="form"
@ -66,6 +72,10 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
render={({ field, fieldState }) => (
<TextInput
{...field}
onChange={(event) => {
field.onChange(event);
clearError();
}}
type="tel"
dir="ltr"
inputMode="numeric"
@ -78,12 +88,7 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
)}
/>
{isUnknownPhone && (
<Link
href={registerHref}
onClick={carryPhone}
icon="arrow-left"
standalone
>
<Link href={registerHref} icon="arrow-left" standalone>
{t('login.register-with-phone')}
</Link>
)}
@ -97,6 +102,11 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
>
{t('login.submit')}
</Button>
{subscribe && (
<Banner tone="info" icon="lock">
{t('login.subscribe.notice')}
</Banner>
)}
</FlexBox>
<FlexBox
alignItems="items-center"
@ -106,9 +116,7 @@ export function LoginStep({ size, supportPlacement }: LoginStepProps) {
<Typography tag="span" variant="body-sm" color="secondary">
{t('login.no-account')}
</Typography>
<Link href={registerHref} onClick={carryPhone}>
{t('login.register')}
</Link>
<Link href={registerHref}>{t('login.register')}</Link>
</FlexBox>
<FlexBox justifyContent="justify-center" className="mt-auto">
<SupportEntry trigger="link" placement={supportPlacement} />

View File

@ -0,0 +1,74 @@
'use client';
import { FlexBox } from '@lumina/island/atoms/flex-box';
import { StateArt } from '@lumina/island/atoms/state-art';
import { Typography } from '@lumina/island/atoms/typography';
import { SkeletonPreset } from '@lumina/island/organisms/skeleton-preset';
import { useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useLoginSuspendedPage } from '../../../../../../../../features/auth';
import { useAuthRoutes } from '../../../../../../../navigation';
import { SupportEntry } from '../../../../../../organisms/support-entry';
import type { LoginSuspendedStepProps } from './types';
/**
* A valid code for a suspended account (S6 1.11, 2.1, 3.1): no session, nothing else reachable,
* one way out to support. Amber, because a suspension is a state, not an error. The admin's reason
* shows when there is one. Focus starts on the heading, as the page replaces the code step.
*/
export function LoginSuspendedStep({
size,
supportPlacement,
layout,
}: LoginSuspendedStepProps) {
const { t } = useTranslation('auth');
const routes = useAuthRoutes();
const { suspension } = useLoginSuspendedPage({ loginHref: routes.login });
const headingRef = useRef<HTMLHeadingElement>(null);
useEffect(() => headingRef.current?.focus(), [suspension]);
if (!suspension) {
// The page's own skeleton, while a reload goes back to login.
return <SkeletonPreset preset="state" label={t('loading')} />;
}
return (
<FlexBox
direction="flex-col"
alignItems="items-center"
gap="gap-4"
className={
layout === 'mobile' ? 'flex-1 pt-6 text-center' : 'pt-6 text-center'
}
>
<StateArt icon="ban" tone="warning" />
<FlexBox direction="flex-col" alignItems="items-center" gap="gap-2">
<Typography
ref={headingRef}
tabIndex={-1}
tag="h1"
variant="heading-md"
className="outline-none"
>
{t('suspended.title')}
</Typography>
<Typography color="secondary">
{suspension.reason
? t('suspended.reason', { reason: suspension.reason })
: t('suspended.description')}
</Typography>
</FlexBox>
<FlexBox
direction="flex-col"
className={layout === 'mobile' ? 'mt-auto w-full' : 'mt-2 w-full'}
>
<SupportEntry
trigger="button"
placement={supportPlacement}
size={size}
/>
</FlexBox>
</FlexBox>
);
}

Some files were not shown because too many files have changed in this diff Show More