@aiveth/react 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 +6 -0
- package/README.md +14 -0
- package/dist/brand.d.ts +41 -0
- package/dist/brand.js +55 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/react.d.ts +10 -1
- package/dist/react.js +13 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0 — 2026-11-25
|
|
4
|
+
|
|
5
|
+
- `<AivethButton>`: "Sign in" in the organization's own look (Aiveth → Branding: colours light
|
|
6
|
+
and dark, corners, font, filled or outlined, logo with `showLogo`), read from Aiveth's public
|
|
7
|
+
`/v1/branding/public`. Also `BrandedButton` and `useBrandLook` for your own button.
|
|
8
|
+
|
|
3
9
|
## 0.3.0 — 2026-11-25
|
|
4
10
|
|
|
5
11
|
- Same version as the new `@aiveth/nextjs` (one number for every release of Aiveth's SDKs). No
|
package/README.md
CHANGED
|
@@ -23,6 +23,20 @@ const token = await getAccessToken(); // Authorization: Bearer … for your API
|
|
|
23
23
|
- Refresh tokens (`offline_access`, asked by default) are swapped at every use.
|
|
24
24
|
- One app belongs to one organization in Aiveth, so there is no organization switcher.
|
|
25
25
|
|
|
26
|
+
## Sign in in your organization's own look
|
|
27
|
+
|
|
28
|
+
`<AivethButton>` draws "Sign in" with what you set in Aiveth → Branding — colours (light and
|
|
29
|
+
dark), corners, font, filled or outlined — so your page and Aiveth's sign-in page look the same:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { AivethButton } from '@aiveth/react';
|
|
33
|
+
|
|
34
|
+
<AivethButton returnTo="/dashboard" showLogo>Sign in to Acme</AivethButton>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
It reads Aiveth's public `/v1/branding/public?client_id=…` (nothing secret). For your own button,
|
|
38
|
+
use `useBrandLook(address)` and `<BrandedButton look={…} onClick={…}>`.
|
|
39
|
+
|
|
26
40
|
## Acting for others (support signed in as a person)
|
|
27
41
|
|
|
28
42
|
When a support person acts as someone (Aiveth → Security → Acting for others), the ID token
|
package/dist/brand.d.ts
ADDED
|
@@ -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-runtime").JSX.Element;
|
package/dist/brand.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* "Sign in with Aiveth" in the organization's own look, on the app's OWN page (Suvichaar asked:
|
|
3
|
+
* the branding set in Aiveth didn't reach their login page). The look is what anyone already sees
|
|
4
|
+
* on the organization's sign-in card — Aiveth's public `GET /v1/branding/public?client_id=…`:
|
|
5
|
+
* colours (light and dark), corner radius, font, a filled or outlined button, the logo. Nothing
|
|
6
|
+
* secret; the sign-in itself still happens on Aiveth's page. Kept the same in @aiveth/nextjs. */
|
|
7
|
+
import { useEffect, useState, useSyncExternalStore } from 'react';
|
|
8
|
+
const looks = new Map();
|
|
9
|
+
/** One fetch per address for the whole page; Aiveth's own look when it can't be read. */
|
|
10
|
+
export function useBrandLook(address) {
|
|
11
|
+
const [look, setLook] = useState(null);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!address)
|
|
14
|
+
return;
|
|
15
|
+
let live = true;
|
|
16
|
+
if (!looks.has(address)) {
|
|
17
|
+
looks.set(address, fetch(address).then((r) => (r.ok ? r.json() : { custom: false }))
|
|
18
|
+
.catch(() => ({ custom: false })));
|
|
19
|
+
}
|
|
20
|
+
void looks.get(address).then((l) => { if (live)
|
|
21
|
+
setLook(l); });
|
|
22
|
+
return () => { live = false; };
|
|
23
|
+
}, [address]);
|
|
24
|
+
return look;
|
|
25
|
+
}
|
|
26
|
+
const darkQuery = () => typeof globalThis.matchMedia === 'function' ? globalThis.matchMedia('(prefers-color-scheme: dark)') : null;
|
|
27
|
+
function useDark(appearance) {
|
|
28
|
+
const device = useSyncExternalStore((on) => { const q = darkQuery(); q?.addEventListener('change', on); return () => q?.removeEventListener('change', on); }, () => darkQuery()?.matches ?? false, () => false);
|
|
29
|
+
return appearance === 'dark' || (appearance !== 'light' && device);
|
|
30
|
+
}
|
|
31
|
+
/** The button itself — a link when `href` is given (Next.js), else a button. */
|
|
32
|
+
export function BrandedButton({ look, children = 'Sign in', showLogo = false, className, style, onClick, href }) {
|
|
33
|
+
const dark = useDark(look?.appearance);
|
|
34
|
+
const mode = dark ? 'dark' : 'light';
|
|
35
|
+
const c = look?.custom ? look.colours?.[mode] : undefined;
|
|
36
|
+
const outlined = look?.button_style === 'outlined';
|
|
37
|
+
const logo = dark ? look?.logo_dark ?? look?.logo : look?.logo ?? look?.logo_dark;
|
|
38
|
+
const family = look?.font?.url ? `'Aiveth ${look.font.family}', system-ui, sans-serif` : undefined;
|
|
39
|
+
const css = {
|
|
40
|
+
display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 8, minHeight: 44,
|
|
41
|
+
padding: '0 18px', cursor: 'pointer', textDecoration: 'none', fontSize: 15, fontWeight: 500,
|
|
42
|
+
borderRadius: look?.radius ?? 10, fontFamily: family, border: 0,
|
|
43
|
+
background: c ? (outlined ? 'transparent' : c.button) : '#0C0A09',
|
|
44
|
+
color: c ? (outlined ? c.button : c.button_text) : '#FAFAF9',
|
|
45
|
+
boxShadow: c && outlined ? `inset 0 0 0 1.5px ${c.button}` : 'none',
|
|
46
|
+
...style,
|
|
47
|
+
};
|
|
48
|
+
const inner = _jsxs(_Fragment, { children: [showLogo && logo && _jsx("img", { src: logo, alt: "", style: { height: 20, width: 'auto' } }), children] });
|
|
49
|
+
const face = look?.font?.url
|
|
50
|
+
? _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}` })
|
|
51
|
+
: null;
|
|
52
|
+
return href
|
|
53
|
+
? _jsxs(_Fragment, { children: [face, _jsx("a", { href: href, className: className, style: css, children: inner })] })
|
|
54
|
+
: _jsxs(_Fragment, { children: [face, _jsx("button", { type: "button", className: className, style: css, onClick: onClick, children: inner })] });
|
|
55
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { AivethClient, RefusedError, SignInError, claimsOf, type Actor, type AivethConfig, type Returned, type User } from './client.js';
|
|
2
|
-
export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, SignOutButton, UserButton, ActingBanner, type AivethProviderProps, type UseAiveth } from './react.js';
|
|
2
|
+
export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, AivethButton, SignOutButton, UserButton, ActingBanner, type AivethProviderProps, type UseAiveth } from './react.js';
|
|
3
|
+
export { BrandedButton, useBrandLook, type BrandLook, type BrandedButtonProps } from './brand.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { AivethClient, RefusedError, SignInError, claimsOf } from './client.js';
|
|
2
|
-
export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, SignOutButton, UserButton, ActingBanner } from './react.js';
|
|
2
|
+
export { AivethProvider, useAiveth, SignedIn, SignedOut, SignInButton, AivethButton, SignOutButton, UserButton, ActingBanner } from './react.js';
|
|
3
|
+
export { BrandedButton, useBrandLook } from './brand.js';
|
package/dist/react.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 Actor, type AivethConfig, type User } from './client.js';
|
|
3
3
|
export interface AivethProviderProps extends AivethConfig {
|
|
4
4
|
children: ReactNode;
|
|
@@ -40,6 +40,15 @@ export declare function SignInButton({ children, returnTo, className }: {
|
|
|
40
40
|
returnTo?: string;
|
|
41
41
|
className?: string;
|
|
42
42
|
}): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
/** "Sign in" in the organization's own look (its colours, corners, font, filled or outlined —
|
|
44
|
+
* as set in Aiveth → Branding), so the app's page and Aiveth's sign-in page look the same. */
|
|
45
|
+
export declare function AivethButton({ children, returnTo, showLogo, className, style }: {
|
|
46
|
+
children?: ReactNode;
|
|
47
|
+
returnTo?: string;
|
|
48
|
+
showLogo?: boolean;
|
|
49
|
+
className?: string;
|
|
50
|
+
style?: CSSProperties;
|
|
51
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
43
52
|
export declare function SignOutButton({ children, className }: {
|
|
44
53
|
children?: ReactNode;
|
|
45
54
|
className?: string;
|
package/dist/react.js
CHANGED
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
* WorkOS give — <SignedIn>, <SignedOut>, <SignInButton>, <SignOutButton>, <UserButton>. Sign-in
|
|
4
4
|
* itself happens on Aiveth's page (RFC 8252). */
|
|
5
5
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
6
|
+
import { BrandedButton, useBrandLook } from './brand.js';
|
|
6
7
|
import { AivethClient } from './client.js';
|
|
7
8
|
const Context = createContext(null);
|
|
8
9
|
/** Put it around your app. On the return address it finishes the sign-in by itself. */
|
|
@@ -29,7 +30,8 @@ export function AivethProvider({ children, onSignedIn, ...config }) {
|
|
|
29
30
|
})
|
|
30
31
|
.finally(() => setLoaded(true));
|
|
31
32
|
}, [client, onSignedIn]);
|
|
32
|
-
|
|
33
|
+
const brandAddress = `${config.issuer.replace(/\/+$/, '')}/v1/branding/public?client_id=${encodeURIComponent(config.clientId)}`;
|
|
34
|
+
return _jsx(Context.Provider, { value: { client, brandAddress, isLoaded, error }, children: children });
|
|
33
35
|
}
|
|
34
36
|
function actorOf(user) {
|
|
35
37
|
const act = user?.act;
|
|
@@ -61,6 +63,16 @@ export function SignInButton({ children = 'Sign in', returnTo, className }) {
|
|
|
61
63
|
const { signIn } = useAiveth();
|
|
62
64
|
return _jsx("button", { type: "button", className: className, onClick: () => { void signIn({ returnTo }); }, children: children });
|
|
63
65
|
}
|
|
66
|
+
/** "Sign in" in the organization's own look (its colours, corners, font, filled or outlined —
|
|
67
|
+
* as set in Aiveth → Branding), so the app's page and Aiveth's sign-in page look the same. */
|
|
68
|
+
export function AivethButton({ children = 'Sign in', returnTo, showLogo, className, style }) {
|
|
69
|
+
const found = useContext(Context);
|
|
70
|
+
if (!found)
|
|
71
|
+
throw new Error('AivethButton needs <AivethProvider> around your app.');
|
|
72
|
+
const { signIn } = useAiveth();
|
|
73
|
+
const look = useBrandLook(found.brandAddress);
|
|
74
|
+
return _jsx(BrandedButton, { look: look, showLogo: showLogo, className: className, style: style, onClick: () => { void signIn({ returnTo }); }, children: children });
|
|
75
|
+
}
|
|
64
76
|
export function SignOutButton({ children = 'Sign out', className }) {
|
|
65
77
|
const { signOut } = useAiveth();
|
|
66
78
|
return _jsx("button", { type: "button", className: className, onClick: () => { void signOut(); }, children: children });
|
package/package.json
CHANGED