@aiveth/nextjs 0.3.0 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0 — 2026-11-25
4
+
5
+ - `<AivethButton>` (`@aiveth/nextjs/client`): "Sign in" in the organization's own look
6
+ (Aiveth → Branding). The proxy answers a new route, `/auth/branding`, reading it from Aiveth on
7
+ the server.
8
+
3
9
  ## 0.3.0 — 2026-11-25 — first release
4
10
 
5
11
  - `aivethProxy()` for `proxy.ts` (Next.js 16) or `middleware.ts` (15): answers `/auth/login`,
package/README.md CHANGED
@@ -62,6 +62,18 @@ import { SignedIn, SignedOut, SignInButton, UserButton, useUser } from '@aiveth/
62
62
  <SignedIn><UserButton /></SignedIn>
63
63
  ```
64
64
 
65
+ ## Sign in in your organization's own look
66
+
67
+ ```tsx
68
+ 'use client';
69
+ import { AivethButton } from '@aiveth/nextjs/client';
70
+
71
+ <AivethButton returnTo="/dashboard" showLogo>Sign in to Acme</AivethButton>
72
+ ```
73
+
74
+ It uses what you set in Aiveth → Branding (colours, corners, font, filled or outlined, logo),
75
+ read by the proxy from Aiveth on the server at `/auth/branding`.
76
+
65
77
  ## Routes the proxy answers
66
78
 
67
79
  | Route | What it does |
@@ -70,3 +82,4 @@ import { SignedIn, SignedOut, SignInButton, UserButton, useUser } from '@aiveth/
70
82
  | `/auth/callback` | Aiveth's answer: checks it and writes the session |
71
83
  | `/auth/logout` | Clears the session, then signs out at Aiveth and comes back |
72
84
  | `/auth/session` | `{ user }` for the browser — never a token |
85
+ | `/auth/branding` | The organization's look for `AivethButton` (public, cached 5 minutes) |
@@ -0,0 +1,41 @@
1
+ import { type CSSProperties, type ReactNode } from 'react';
2
+ export interface BrandLook {
3
+ custom: boolean;
4
+ name?: string;
5
+ appearance?: 'system' | 'light' | 'dark';
6
+ radius?: number;
7
+ colours?: Record<'light' | 'dark', {
8
+ page: string;
9
+ button: string;
10
+ button_text: string;
11
+ link: string;
12
+ }>;
13
+ more_colours?: Record<'light' | 'dark', {
14
+ card: string;
15
+ input: string;
16
+ border: string;
17
+ button_hover: string;
18
+ }>;
19
+ button_style?: 'filled' | 'outlined';
20
+ font?: {
21
+ family: string;
22
+ url: string | null;
23
+ };
24
+ logo?: string | null;
25
+ logo_dark?: string | null;
26
+ icon?: string | null;
27
+ }
28
+ /** One fetch per address for the whole page; Aiveth's own look when it can't be read. */
29
+ export declare function useBrandLook(address: string | null): BrandLook | null;
30
+ export interface BrandedButtonProps {
31
+ look: BrandLook | null;
32
+ children?: ReactNode;
33
+ /** The organization's logo beside the words. */
34
+ showLogo?: boolean;
35
+ className?: string;
36
+ style?: CSSProperties;
37
+ onClick?: () => void;
38
+ href?: string;
39
+ }
40
+ /** The button itself — a link when `href` is given (Next.js), else a button. */
41
+ export declare function BrandedButton({ look, children, showLogo, className, style, onClick, href }: BrandedButtonProps): import("react").JSX.Element;
package/dist/brand.js ADDED
@@ -0,0 +1,56 @@
1
+ 'use client';
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /* "Sign in with Aiveth" in the organization's own look, on the app's OWN page (Suvichaar asked:
4
+ * the branding set in Aiveth didn't reach their login page). The look is what anyone already sees
5
+ * on the organization's sign-in card — Aiveth's public `GET /v1/branding/public?client_id=…`:
6
+ * colours (light and dark), corner radius, font, a filled or outlined button, the logo. Nothing
7
+ * secret; the sign-in itself still happens on Aiveth's page. Kept the same in @aiveth/react (a copy: each package stands alone). */
8
+ import { useEffect, useState, useSyncExternalStore } from 'react';
9
+ const looks = new Map();
10
+ /** One fetch per address for the whole page; Aiveth's own look when it can't be read. */
11
+ export function useBrandLook(address) {
12
+ const [look, setLook] = useState(null);
13
+ useEffect(() => {
14
+ if (!address)
15
+ return;
16
+ let live = true;
17
+ if (!looks.has(address)) {
18
+ looks.set(address, fetch(address).then((r) => (r.ok ? r.json() : { custom: false }))
19
+ .catch(() => ({ custom: false })));
20
+ }
21
+ void looks.get(address).then((l) => { if (live)
22
+ setLook(l); });
23
+ return () => { live = false; };
24
+ }, [address]);
25
+ return look;
26
+ }
27
+ const darkQuery = () => typeof globalThis.matchMedia === 'function' ? globalThis.matchMedia('(prefers-color-scheme: dark)') : null;
28
+ function useDark(appearance) {
29
+ const device = useSyncExternalStore((on) => { const q = darkQuery(); q?.addEventListener('change', on); return () => q?.removeEventListener('change', on); }, () => darkQuery()?.matches ?? false, () => false);
30
+ return appearance === 'dark' || (appearance !== 'light' && device);
31
+ }
32
+ /** The button itself — a link when `href` is given (Next.js), else a button. */
33
+ export function BrandedButton({ look, children = 'Sign in', showLogo = false, className, style, onClick, href }) {
34
+ const dark = useDark(look?.appearance);
35
+ const mode = dark ? 'dark' : 'light';
36
+ const c = look?.custom ? look.colours?.[mode] : undefined;
37
+ const outlined = look?.button_style === 'outlined';
38
+ const logo = dark ? look?.logo_dark ?? look?.logo : look?.logo ?? look?.logo_dark;
39
+ const family = look?.font?.url ? `'Aiveth ${look.font.family}', system-ui, sans-serif` : undefined;
40
+ const css = {
41
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 8, minHeight: 44,
42
+ padding: '0 18px', cursor: 'pointer', textDecoration: 'none', fontSize: 15, fontWeight: 500,
43
+ borderRadius: look?.radius ?? 10, fontFamily: family, border: 0,
44
+ background: c ? (outlined ? 'transparent' : c.button) : '#0C0A09',
45
+ color: c ? (outlined ? c.button : c.button_text) : '#FAFAF9',
46
+ boxShadow: c && outlined ? `inset 0 0 0 1.5px ${c.button}` : 'none',
47
+ ...style,
48
+ };
49
+ const inner = _jsxs(_Fragment, { children: [showLogo && logo && _jsx("img", { src: logo, alt: "", style: { height: 20, width: 'auto' } }), children] });
50
+ const face = look?.font?.url
51
+ ? _jsx("style", { children: `@font-face{font-family:'Aiveth ${look.font.family}';src:url(${look.font.url}) format('woff2');font-weight:100 900;font-display:swap}` })
52
+ : null;
53
+ return href
54
+ ? _jsxs(_Fragment, { children: [face, _jsx("a", { href: href, className: className, style: css, children: inner })] })
55
+ : _jsxs(_Fragment, { children: [face, _jsx("button", { type: "button", className: className, style: css, onClick: onClick, children: inner })] });
56
+ }
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ReactNode } from 'react';
1
+ import { type CSSProperties, type ReactNode } from 'react';
2
2
  import type { User } from './session.js';
3
3
  interface UseUser {
4
4
  user: User | null;
@@ -23,6 +23,15 @@ export declare function SignInButton({ children, returnTo, className }: {
23
23
  returnTo?: string;
24
24
  className?: string;
25
25
  }): import("react").JSX.Element;
26
+ /** "Sign in" in the organization's own look (Aiveth → Branding: colours, corners, font, filled
27
+ * or outlined), so this page and Aiveth's sign-in page look the same. */
28
+ export declare function AivethButton({ children, returnTo, showLogo, className, style }: {
29
+ children?: ReactNode;
30
+ returnTo?: string;
31
+ showLogo?: boolean;
32
+ className?: string;
33
+ style?: CSSProperties;
34
+ }): import("react").JSX.Element;
26
35
  export declare function SignOutButton({ children, className }: {
27
36
  children?: ReactNode;
28
37
  className?: string;
package/dist/client.js CHANGED
@@ -3,6 +3,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  /* The person in the browser. The profile comes from `/auth/session` (the cookie is HttpOnly: no
4
4
  * token ever reaches the browser). Sign in and out are links to the proxy's routes. */
5
5
  import { createContext, useCallback, useContext, useEffect, useState } from 'react';
6
+ import { BrandedButton, useBrandLook } from './brand.js';
6
7
  import { ROUTES } from './config.js';
7
8
  const Ctx = createContext(null);
8
9
  /** `initialUser`: pass `await getUser()` from a Server Component to skip the first fetch. */
@@ -46,6 +47,13 @@ export function SignInButton({ children = 'Sign in', returnTo, className }) {
46
47
  const href = returnTo ? `${ROUTES.login}?${new URLSearchParams({ returnTo })}` : ROUTES.login;
47
48
  return _jsx("a", { href: href, className: className, children: children });
48
49
  }
50
+ /** "Sign in" in the organization's own look (Aiveth → Branding: colours, corners, font, filled
51
+ * or outlined), so this page and Aiveth's sign-in page look the same. */
52
+ export function AivethButton({ children = 'Sign in', returnTo, showLogo, className, style }) {
53
+ const look = useBrandLook(ROUTES.branding);
54
+ const href = returnTo ? `${ROUTES.login}?${new URLSearchParams({ returnTo })}` : ROUTES.login;
55
+ return _jsx(BrandedButton, { look: look, href: href, showLogo: showLogo, className: className, style: style, children: children });
56
+ }
49
57
  export function SignOutButton({ children = 'Sign out', className }) {
50
58
  return _jsx("a", { href: ROUTES.logout, className: className, children: children });
51
59
  }
package/dist/config.d.ts CHANGED
@@ -19,6 +19,8 @@ export declare const ROUTES: {
19
19
  readonly callback: "/auth/callback";
20
20
  readonly logout: "/auth/logout";
21
21
  readonly session: "/auth/session";
22
+ /** The organization's look for this app (`AivethButton`), read from Aiveth on the server. */
23
+ readonly branding: "/auth/branding";
22
24
  };
23
25
  /** Use these settings instead of the environment's (or on top of them). */
24
26
  export declare function configureAiveth(settings: Partial<AivethNextConfig>): void;
package/dist/config.js CHANGED
@@ -4,6 +4,8 @@ export const ROUTES = {
4
4
  callback: '/auth/callback',
5
5
  logout: '/auth/logout',
6
6
  session: '/auth/session',
7
+ /** The organization's look for this app (`AivethButton`), read from Aiveth on the server. */
8
+ branding: '/auth/branding',
7
9
  };
8
10
  const DEFAULT_SCOPE = 'openid profile email offline_access';
9
11
  let current = null;
@@ -8,3 +8,7 @@ export declare function callback(req: NextRequest, c: AivethNextConfig): Promise
8
8
  export declare function logout(req: NextRequest, c: AivethNextConfig): Promise<NextResponse>;
9
9
  /** Who is signed in, for the browser (`AivethProvider`): the profile only, never a token. */
10
10
  export declare function sessionJson(req: NextRequest, c: AivethNextConfig): Promise<NextResponse>;
11
+ /** The organization's look (Aiveth → Branding) for `AivethButton`: Aiveth's public
12
+ * `/v1/branding/public` for THIS app, fetched here so the browser never needs the client id or
13
+ * another site. Aiveth's own look when it can't be read; nothing secret either way. */
14
+ export declare function brandingJson(_req: NextRequest, c: AivethNextConfig): Promise<NextResponse>;
package/dist/handlers.js CHANGED
@@ -1,4 +1,5 @@
1
- /* The routes the proxy answers: /auth/login, /auth/callback, /auth/logout, /auth/session. */
1
+ /* The routes the proxy answers: /auth/login, /auth/callback, /auth/logout, /auth/session,
2
+ * /auth/branding. */
2
3
  import { NextResponse } from 'next/server';
3
4
  import { ROUTES, safeReturnTo } from './config.js';
4
5
  import { AivethAuthError, authorizeUrl, challengeOf, exchangeCode, logoutUrl, randomValue } from './oidc.js';
@@ -60,3 +61,16 @@ export async function sessionJson(req, c) {
60
61
  const session = await readSession(req.cookies, c.cookieSecret);
61
62
  return NextResponse.json({ user: session?.user ?? null }, { headers: { 'Cache-Control': 'no-store' } });
62
63
  }
64
+ /** The organization's look (Aiveth → Branding) for `AivethButton`: Aiveth's public
65
+ * `/v1/branding/public` for THIS app, fetched here so the browser never needs the client id or
66
+ * another site. Aiveth's own look when it can't be read; nothing secret either way. */
67
+ export async function brandingJson(_req, c) {
68
+ const headers = { 'Cache-Control': 'public, max-age=300' };
69
+ try {
70
+ const res = await (c.fetch ?? fetch)(`${c.baseUrl}/v1/branding/public?${new URLSearchParams({ client_id: c.clientId })}`, { cache: 'no-store' });
71
+ return NextResponse.json(res.ok ? await res.json() : { custom: false }, { headers });
72
+ }
73
+ catch {
74
+ return NextResponse.json({ custom: false }, { headers });
75
+ }
76
+ }
package/dist/proxy.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * page, the Route Handler, the Server Action) — CVE-2025-29927 slipped past middleware alone. */
6
6
  import { NextResponse } from 'next/server';
7
7
  import { ROUTES, config } from './config.js';
8
- import { callback, login, logout, secureFor, sessionJson, write } from './handlers.js';
8
+ import { brandingJson, callback, login, logout, secureFor, sessionJson, write } from './handlers.js';
9
9
  import { refreshSession } from './oidc.js';
10
10
  import { clearedSessionCookies, now, readSession, sessionCookies } from './session.js';
11
11
  /** A new access token this long before the old one ends. */
@@ -42,6 +42,8 @@ export function aivethProxy(options = {}) {
42
42
  return logout(req, c);
43
43
  if (path === ROUTES.session)
44
44
  return sessionJson(req, c);
45
+ if (path === ROUTES.branding)
46
+ return brandingJson(req, c);
45
47
  let session = await readSession(req.cookies, c.cookieSecret);
46
48
  let cookies = [];
47
49
  if (session) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiveth/nextjs",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Aiveth by Gooclaim for Next.js: sign in on Aiveth's page, an encrypted session cookie, the user on the server and in the browser.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Gooclaim",