@drmhse/authos-react 0.1.0 → 0.1.2

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/README.md ADDED
@@ -0,0 +1,277 @@
1
+ # @drmhse/authos-react
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@drmhse/authos-react)](https://www.npmjs.com/package/@drmhse/authos-react)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ React adapter for [AuthOS](https://authos.dev) - the multi-tenant authentication platform. Provides React hooks, components, and Next.js integration.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @drmhse/authos-react
12
+ ```
13
+
14
+ Peer dependencies:
15
+ ```bash
16
+ npm install react react-dom
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ Wrap your app with `AuthOSProvider`, then use the hooks and components throughout your app.
22
+
23
+ ```tsx
24
+ import { AuthOSProvider } from '@drmhse/authos-react';
25
+
26
+ function App() {
27
+ return (
28
+ <AuthOSProvider
29
+ config={{
30
+ baseURL: 'https://sso.example.com'
31
+ }}
32
+ >
33
+ <YourApp />
34
+ </AuthOSProvider>
35
+ );
36
+ }
37
+ ```
38
+
39
+ ## Components
40
+
41
+ ### SignIn
42
+
43
+ Pre-built sign-in form with email/password and OAuth provider buttons.
44
+
45
+ ```tsx
46
+ import { SignIn } from '@drmhse/authos-react';
47
+
48
+ function LoginPage() {
49
+ return (
50
+ <SignIn
51
+ onSuccess={() => console.log('Logged in!')}
52
+ onError={(err) => console.error(err)}
53
+ />
54
+ );
55
+ }
56
+ ```
57
+
58
+ **Props:**
59
+ | Prop | Type | Description |
60
+ |------|------|-------------|
61
+ | `onSuccess` | `() => void` | Callback after successful login |
62
+ | `onError` | `(error: Error) => void` | Callback on login error |
63
+
64
+ ### SignUp
65
+
66
+ Registration form for new users.
67
+
68
+ ```tsx
69
+ import { SignUp } from '@drmhse/authos-react';
70
+
71
+ function RegisterPage() {
72
+ return (
73
+ <SignUp
74
+ onSuccess={() => console.log('Registered!')}
75
+ onError={(err) => console.error(err)}
76
+ />
77
+ );
78
+ }
79
+ ```
80
+
81
+ **Props:** Same as `SignIn`
82
+
83
+ ### UserButton
84
+
85
+ User menu button that shows avatar/name and dropdown with profile/signout.
86
+
87
+ ```tsx
88
+ import { UserButton } from '@drmhse/authos-react';
89
+
90
+ function Header() {
91
+ return <UserButton />;
92
+ }
93
+ ```
94
+
95
+ ### OrganizationSwitcher
96
+
97
+ Dropdown to switch between organizations (for multi-tenant users).
98
+
99
+ ```tsx
100
+ import { OrganizationSwitcher } from '@drmhse/authos-react';
101
+
102
+ function Sidebar() {
103
+ return <OrganizationSwitcher />;
104
+ }
105
+ ```
106
+
107
+ ### Protect
108
+
109
+ Conditional rendering based on user permissions.
110
+
111
+ ```tsx
112
+ import { Protect } from '@drmhse/authos-react';
113
+
114
+ function AdminPanel() {
115
+ return (
116
+ <Protect
117
+ permission="admin:access"
118
+ fallback={<p>Access denied. Admins only.</p>}
119
+ >
120
+ <AdminDashboard />
121
+ </Protect>
122
+ );
123
+ }
124
+ ```
125
+
126
+ **Props:**
127
+ | Prop | Type | Description |
128
+ |------|------|-------------|
129
+ | `permission` | `string` | Required permission to access content |
130
+ | `fallback` | `ReactNode` | Shown when user lacks permission |
131
+ | `children` | `ReactNode` | Protected content |
132
+
133
+ ## Hooks
134
+
135
+ ### useAuthOS
136
+
137
+ Access the AuthOS client directly.
138
+
139
+ ```tsx
140
+ import { useAuthOS } from '@drmhse/authos-react';
141
+
142
+ function Profile() {
143
+ const { client, isAuthenticated, isLoading } = useAuthOS();
144
+
145
+ if (isLoading) return <div>Loading...</div>;
146
+ if (!isAuthenticated) return <div>Please log in</div>;
147
+
148
+ const handleLogout = async () => {
149
+ await client.auth.logout();
150
+ };
151
+
152
+ return (
153
+ <div>
154
+ <button onClick={handleLogout}>Logout</button>
155
+ </div>
156
+ );
157
+ }
158
+ ```
159
+
160
+ ### useUser
161
+
162
+ Get the current user's profile.
163
+
164
+ ```tsx
165
+ import { useUser } from '@drmhse/authos-react';
166
+
167
+ function UserProfile() {
168
+ const { user, isLoading } = useUser();
169
+
170
+ if (isLoading) return <div>Loading...</div>;
171
+ return <div>Welcome, {user?.email}</div>;
172
+ }
173
+ ```
174
+
175
+ ### useOrganization
176
+
177
+ Get the current organization and list of organizations.
178
+
179
+ ```tsx
180
+ import { useOrganization } from '@drmhse/authos-react';
181
+
182
+ function OrgInfo() {
183
+ const { currentOrganization, organizations } = useOrganization();
184
+
185
+ return (
186
+ <div>
187
+ <h3>{currentOrganization?.name}</h3>
188
+ <ul>
189
+ {organizations.map((org) => (
190
+ <li key={org.id}>{org.name}</li>
191
+ ))}
192
+ </ul>
193
+ </div>
194
+ );
195
+ }
196
+ ```
197
+
198
+ ### usePermission, useAnyPermission, useAllPermissions
199
+
200
+ Check user permissions.
201
+
202
+ ```tsx
203
+ import { usePermission } from '@drmhse/authos-react';
204
+
205
+ function AdminButton() {
206
+ const canAccessAdmin = usePermission('admin:access');
207
+
208
+ if (!canAccessAdmin) return null;
209
+
210
+ return <button>Admin Panel</button>;
211
+ }
212
+ ```
213
+
214
+ ## Next.js Integration
215
+
216
+ For Next.js App Router, use the middleware and server utilities:
217
+
218
+ ```tsx
219
+ // middleware.ts
220
+ import { authMiddleware } from '@drmhse/authos-react/nextjs';
221
+
222
+ export default authMiddleware();
223
+ ```
224
+
225
+ ```tsx
226
+ // app/dashboard/page.tsx
227
+ import { currentUser } from '@drmhse/authos-react/nextjs';
228
+
229
+ export default async function Dashboard() {
230
+ const user = await currentUser();
231
+
232
+ if (!user) {
233
+ return <div>Please log in</div>;
234
+ }
235
+
236
+ return <div>Welcome, {user.email}</div>;
237
+ }
238
+ ```
239
+
240
+ ## API Reference
241
+
242
+ ### AuthOSProvider Props
243
+
244
+ | Prop | Type | Default | Description |
245
+ |------|------|---------|-------------|
246
+ | `config.baseURL` | `string` | **required** | AuthOS API URL |
247
+ | `config.storage` | `TokenStorage` | `localStorage` | Custom token storage |
248
+ | `config.autoRefresh` | `boolean` | `true` | Auto-refresh expired tokens |
249
+ | `config.onAuthStateChange` | `(user) => void` | - | Callback when auth state changes |
250
+
251
+ ### SsoClient
252
+
253
+ The underlying client from `@drmhse/sso-sdk`. See [SDK docs](https://www.npmjs.com/package/@drmhse/sso-sdk) for full API.
254
+
255
+ ```tsx
256
+ const { client } = useAuthOS();
257
+
258
+ // Authentication
259
+ await client.auth.login({ email, password });
260
+ await client.auth.logout();
261
+ await client.auth.register({ email, password, org_slug });
262
+
263
+ // User
264
+ await client.user.getProfile();
265
+ await client.user.updateProfile({ name });
266
+ await client.user.changePassword({ old, new });
267
+
268
+ // Organizations
269
+ await client.organizations.list();
270
+ await client.organizations.get(slug);
271
+
272
+ // And more...
273
+ ```
274
+
275
+ ## License
276
+
277
+ MIT © DRM HSE
package/dist/index.d.mts CHANGED
@@ -19,6 +19,12 @@ interface AuthOSProviderProps {
19
19
  * Optional: Provide an existing SsoClient instance instead of creating a new one
20
20
  */
21
21
  client?: SsoClient;
22
+ /**
23
+ * Optional: Initial session token from server-side (for SSR hydration).
24
+ * When provided, skips the initial loading state on the client.
25
+ * Typically passed from cookies() in Next.js server components.
26
+ */
27
+ initialSessionToken?: string;
22
28
  }
23
29
  /**
24
30
  * Authentication context state
@@ -122,8 +128,28 @@ interface ProtectProps {
122
128
  * );
123
129
  * }
124
130
  * ```
131
+ *
132
+ * @example With SSR token (Next.js App Router)
133
+ * ```tsx
134
+ * import { cookies } from 'next/headers';
135
+ * import { AuthOSProvider } from '@drmhse/authos-react';
136
+ *
137
+ * export default async function RootLayout({ children }) {
138
+ * const cookieStore = cookies();
139
+ * const token = cookieStore.get('authos_token')?.value;
140
+ *
141
+ * return (
142
+ * <AuthOSProvider
143
+ * config={{ baseURL: 'https://auth.example.com' }}
144
+ * initialSessionToken={token}
145
+ * >
146
+ * {children}
147
+ * </AuthOSProvider>
148
+ * );
149
+ * }
150
+ * ```
125
151
  */
126
- declare function AuthOSProvider({ config, children, client: externalClient }: AuthOSProviderProps): react_jsx_runtime.JSX.Element;
152
+ declare function AuthOSProvider({ config, children, client: externalClient, initialSessionToken }: AuthOSProviderProps): react_jsx_runtime.JSX.Element;
127
153
  /**
128
154
  * Hook to access the AuthOS context.
129
155
  * Must be used within an AuthOSProvider.
package/dist/index.d.ts CHANGED
@@ -19,6 +19,12 @@ interface AuthOSProviderProps {
19
19
  * Optional: Provide an existing SsoClient instance instead of creating a new one
20
20
  */
21
21
  client?: SsoClient;
22
+ /**
23
+ * Optional: Initial session token from server-side (for SSR hydration).
24
+ * When provided, skips the initial loading state on the client.
25
+ * Typically passed from cookies() in Next.js server components.
26
+ */
27
+ initialSessionToken?: string;
22
28
  }
23
29
  /**
24
30
  * Authentication context state
@@ -122,8 +128,28 @@ interface ProtectProps {
122
128
  * );
123
129
  * }
124
130
  * ```
131
+ *
132
+ * @example With SSR token (Next.js App Router)
133
+ * ```tsx
134
+ * import { cookies } from 'next/headers';
135
+ * import { AuthOSProvider } from '@drmhse/authos-react';
136
+ *
137
+ * export default async function RootLayout({ children }) {
138
+ * const cookieStore = cookies();
139
+ * const token = cookieStore.get('authos_token')?.value;
140
+ *
141
+ * return (
142
+ * <AuthOSProvider
143
+ * config={{ baseURL: 'https://auth.example.com' }}
144
+ * initialSessionToken={token}
145
+ * >
146
+ * {children}
147
+ * </AuthOSProvider>
148
+ * );
149
+ * }
150
+ * ```
125
151
  */
126
- declare function AuthOSProvider({ config, children, client: externalClient }: AuthOSProviderProps): react_jsx_runtime.JSX.Element;
152
+ declare function AuthOSProvider({ config, children, client: externalClient, initialSessionToken }: AuthOSProviderProps): react_jsx_runtime.JSX.Element;
127
153
  /**
128
154
  * Hook to access the AuthOS context.
129
155
  * Must be used within an AuthOSProvider.
package/dist/index.js CHANGED
@@ -6,15 +6,22 @@ var jsxRuntime = require('react/jsx-runtime');
6
6
 
7
7
  // src/context.tsx
8
8
  var AuthOSContext = react.createContext(null);
9
- function AuthOSProvider({ config, children, client: externalClient }) {
9
+ function AuthOSProvider({ config, children, client: externalClient, initialSessionToken }) {
10
10
  const clientRef = react.useRef(null);
11
11
  if (!clientRef.current) {
12
12
  clientRef.current = externalClient ?? new ssoSdk.SsoClient(config);
13
13
  }
14
14
  const client = clientRef.current;
15
+ const hasInitialToken = react.useRef(!!initialSessionToken);
16
+ react.useEffect(() => {
17
+ if (initialSessionToken && hasInitialToken.current) {
18
+ client.setSession({ access_token: initialSessionToken });
19
+ hasInitialToken.current = false;
20
+ }
21
+ }, [client, initialSessionToken]);
15
22
  const [user, setUser] = react.useState(null);
16
23
  const [organization, setOrganization] = react.useState(null);
17
- const [isLoading, setIsLoading] = react.useState(true);
24
+ const [isLoading, setIsLoading] = react.useState(!initialSessionToken);
18
25
  const refreshUser = react.useCallback(async () => {
19
26
  try {
20
27
  const profile = await client.user.getProfile();
package/dist/index.mjs CHANGED
@@ -1,19 +1,26 @@
1
- import { createContext, useRef, useState, useCallback, useEffect, useMemo, useContext } from 'react';
1
+ import { createContext, useRef, useEffect, useState, useCallback, useMemo, useContext } from 'react';
2
2
  import { SsoClient, SsoApiError } from '@drmhse/sso-sdk';
3
3
  export { AuthErrorCodes, SsoApiError, SsoClient } from '@drmhse/sso-sdk';
4
4
  import { jsx, jsxs } from 'react/jsx-runtime';
5
5
 
6
6
  // src/context.tsx
7
7
  var AuthOSContext = createContext(null);
8
- function AuthOSProvider({ config, children, client: externalClient }) {
8
+ function AuthOSProvider({ config, children, client: externalClient, initialSessionToken }) {
9
9
  const clientRef = useRef(null);
10
10
  if (!clientRef.current) {
11
11
  clientRef.current = externalClient ?? new SsoClient(config);
12
12
  }
13
13
  const client = clientRef.current;
14
+ const hasInitialToken = useRef(!!initialSessionToken);
15
+ useEffect(() => {
16
+ if (initialSessionToken && hasInitialToken.current) {
17
+ client.setSession({ access_token: initialSessionToken });
18
+ hasInitialToken.current = false;
19
+ }
20
+ }, [client, initialSessionToken]);
14
21
  const [user, setUser] = useState(null);
15
22
  const [organization, setOrganization] = useState(null);
16
- const [isLoading, setIsLoading] = useState(true);
23
+ const [isLoading, setIsLoading] = useState(!initialSessionToken);
17
24
  const refreshUser = useCallback(async () => {
18
25
  try {
19
26
  const profile = await client.user.getProfile();
package/dist/nextjs.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
+ import { SsoClient } from '@drmhse/sso-sdk';
2
3
 
3
4
  interface AuthMiddlewareConfig {
4
5
  /**
@@ -143,4 +144,86 @@ declare function auth(): Promise<AuthState>;
143
144
  */
144
145
  declare function getToken(cookieName?: string): Promise<string | null>;
145
146
 
146
- export { type AuthMiddlewareConfig, type AuthState, type AuthUser, auth, authMiddleware, currentUser, getToken };
147
+ /**
148
+ * Configuration for creating an AuthOS client optimized for Next.js
149
+ */
150
+ interface CreateAuthOSClientOptions {
151
+ /**
152
+ * Base URL of the SSO API service
153
+ */
154
+ baseURL: string;
155
+ /**
156
+ * Cookie name for storing the access token
157
+ * @default 'authos_token'
158
+ */
159
+ tokenCookie?: string;
160
+ /**
161
+ * Cookie domain (optional)
162
+ * Use this for subdomain-wide auth
163
+ */
164
+ domain?: string;
165
+ /**
166
+ * Cookie path
167
+ * @default '/'
168
+ */
169
+ path?: string;
170
+ /**
171
+ * SameSite cookie attribute
172
+ * @default 'lax'
173
+ */
174
+ sameSite?: 'strict' | 'lax' | 'none';
175
+ }
176
+ /**
177
+ * Create an SSO client optimized for Next.js with cookie storage.
178
+ *
179
+ * This client uses cookies instead of localStorage, which enables:
180
+ * - Server-side middleware auth checks
181
+ * - SSR hydration without loading flash
182
+ * - Shared auth state across tabs
183
+ *
184
+ * @example
185
+ * ```tsx
186
+ * // lib/authos.ts
187
+ * import { createAuthOSClient } from '@drmhse/authos-react/nextjs';
188
+ *
189
+ * export const authos = createAuthOSClient({
190
+ * baseURL: process.env.NEXT_PUBLIC_AUTHOS_URL!,
191
+ * });
192
+ * ```
193
+ *
194
+ * @example With custom cookie settings
195
+ * ```tsx
196
+ * import { createAuthOSClient } from '@drmhse/authos-react/nextjs';
197
+ *
198
+ * export const authos = createAuthOSClient({
199
+ * baseURL: 'https://auth.example.com',
200
+ * tokenCookie: 'my_app_token',
201
+ * domain: '.example.com', // Share across subdomains
202
+ * });
203
+ * ```
204
+ */
205
+ declare function createAuthOSClient(options: CreateAuthOSClientOptions): SsoClient;
206
+ /**
207
+ * Create an SSO client for use with SSR token fetching.
208
+ * Use this in server components where you need to make API calls
209
+ * with a token from cookies.
210
+ *
211
+ * @example
212
+ * ```tsx
213
+ * // app/dashboard/page.tsx
214
+ * import { createServerClient } from '@drmhse/authos-react/nextjs';
215
+ * import { getToken } from '@drmhse/authos-react/nextjs';
216
+ *
217
+ * export default async function DashboardPage() {
218
+ * const token = await getToken();
219
+ * const client = createServerClient(token);
220
+ *
221
+ * const user = token ? await client.user.getProfile() : null;
222
+ *
223
+ * return <div>Welcome, {user?.email}!</div>;
224
+ * }
225
+ * ```
226
+ */
227
+ declare function createServerClient(token: string, baseURL: string): SsoClient;
228
+
229
+ export { type AuthMiddlewareConfig, type AuthState, type AuthUser, type CreateAuthOSClientOptions, auth, authMiddleware, createAuthOSClient, createServerClient, currentUser, getToken };
package/dist/nextjs.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
+ import { SsoClient } from '@drmhse/sso-sdk';
2
3
 
3
4
  interface AuthMiddlewareConfig {
4
5
  /**
@@ -143,4 +144,86 @@ declare function auth(): Promise<AuthState>;
143
144
  */
144
145
  declare function getToken(cookieName?: string): Promise<string | null>;
145
146
 
146
- export { type AuthMiddlewareConfig, type AuthState, type AuthUser, auth, authMiddleware, currentUser, getToken };
147
+ /**
148
+ * Configuration for creating an AuthOS client optimized for Next.js
149
+ */
150
+ interface CreateAuthOSClientOptions {
151
+ /**
152
+ * Base URL of the SSO API service
153
+ */
154
+ baseURL: string;
155
+ /**
156
+ * Cookie name for storing the access token
157
+ * @default 'authos_token'
158
+ */
159
+ tokenCookie?: string;
160
+ /**
161
+ * Cookie domain (optional)
162
+ * Use this for subdomain-wide auth
163
+ */
164
+ domain?: string;
165
+ /**
166
+ * Cookie path
167
+ * @default '/'
168
+ */
169
+ path?: string;
170
+ /**
171
+ * SameSite cookie attribute
172
+ * @default 'lax'
173
+ */
174
+ sameSite?: 'strict' | 'lax' | 'none';
175
+ }
176
+ /**
177
+ * Create an SSO client optimized for Next.js with cookie storage.
178
+ *
179
+ * This client uses cookies instead of localStorage, which enables:
180
+ * - Server-side middleware auth checks
181
+ * - SSR hydration without loading flash
182
+ * - Shared auth state across tabs
183
+ *
184
+ * @example
185
+ * ```tsx
186
+ * // lib/authos.ts
187
+ * import { createAuthOSClient } from '@drmhse/authos-react/nextjs';
188
+ *
189
+ * export const authos = createAuthOSClient({
190
+ * baseURL: process.env.NEXT_PUBLIC_AUTHOS_URL!,
191
+ * });
192
+ * ```
193
+ *
194
+ * @example With custom cookie settings
195
+ * ```tsx
196
+ * import { createAuthOSClient } from '@drmhse/authos-react/nextjs';
197
+ *
198
+ * export const authos = createAuthOSClient({
199
+ * baseURL: 'https://auth.example.com',
200
+ * tokenCookie: 'my_app_token',
201
+ * domain: '.example.com', // Share across subdomains
202
+ * });
203
+ * ```
204
+ */
205
+ declare function createAuthOSClient(options: CreateAuthOSClientOptions): SsoClient;
206
+ /**
207
+ * Create an SSO client for use with SSR token fetching.
208
+ * Use this in server components where you need to make API calls
209
+ * with a token from cookies.
210
+ *
211
+ * @example
212
+ * ```tsx
213
+ * // app/dashboard/page.tsx
214
+ * import { createServerClient } from '@drmhse/authos-react/nextjs';
215
+ * import { getToken } from '@drmhse/authos-react/nextjs';
216
+ *
217
+ * export default async function DashboardPage() {
218
+ * const token = await getToken();
219
+ * const client = createServerClient(token);
220
+ *
221
+ * const user = token ? await client.user.getProfile() : null;
222
+ *
223
+ * return <div>Welcome, {user?.email}!</div>;
224
+ * }
225
+ * ```
226
+ */
227
+ declare function createServerClient(token: string, baseURL: string): SsoClient;
228
+
229
+ export { type AuthMiddlewareConfig, type AuthState, type AuthUser, type CreateAuthOSClientOptions, auth, authMiddleware, createAuthOSClient, createServerClient, currentUser, getToken };
package/dist/nextjs.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var ssoSdk = require('@drmhse/sso-sdk');
4
+
3
5
  var __create = Object.create;
4
6
  var __defProp = Object.defineProperty;
5
7
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5871,8 +5873,39 @@ async function getToken(cookieName = "authos_token") {
5871
5873
  const cookieStore = await (0, import_headers.cookies)();
5872
5874
  return cookieStore.get(cookieName)?.value ?? null;
5873
5875
  }
5876
+ function createAuthOSClient(options) {
5877
+ const {
5878
+ baseURL,
5879
+ tokenCookie = "authos_token",
5880
+ domain,
5881
+ path = "/",
5882
+ sameSite = "lax"
5883
+ } = options;
5884
+ return new ssoSdk.SsoClient({
5885
+ baseURL,
5886
+ storage: new ssoSdk.CookieStorage({
5887
+ domain,
5888
+ path,
5889
+ secure: true,
5890
+ // Always use secure cookies for auth
5891
+ sameSite,
5892
+ // 30 days default max age
5893
+ maxAge: 30 * 24 * 60 * 60
5894
+ }),
5895
+ storagePrefix: tokenCookie
5896
+ });
5897
+ }
5898
+ function createServerClient(token, baseURL) {
5899
+ return new ssoSdk.SsoClient({
5900
+ baseURL,
5901
+ token
5902
+ // Initial token for server-side use
5903
+ });
5904
+ }
5874
5905
 
5875
5906
  exports.auth = auth;
5876
5907
  exports.authMiddleware = authMiddleware;
5908
+ exports.createAuthOSClient = createAuthOSClient;
5909
+ exports.createServerClient = createServerClient;
5877
5910
  exports.currentUser = currentUser;
5878
5911
  exports.getToken = getToken;
package/dist/nextjs.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { SsoClient, CookieStorage } from '@drmhse/sso-sdk';
2
+
1
3
  var __create = Object.create;
2
4
  var __defProp = Object.defineProperty;
3
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5869,5 +5871,34 @@ async function getToken(cookieName = "authos_token") {
5869
5871
  const cookieStore = await (0, import_headers.cookies)();
5870
5872
  return cookieStore.get(cookieName)?.value ?? null;
5871
5873
  }
5874
+ function createAuthOSClient(options) {
5875
+ const {
5876
+ baseURL,
5877
+ tokenCookie = "authos_token",
5878
+ domain,
5879
+ path = "/",
5880
+ sameSite = "lax"
5881
+ } = options;
5882
+ return new SsoClient({
5883
+ baseURL,
5884
+ storage: new CookieStorage({
5885
+ domain,
5886
+ path,
5887
+ secure: true,
5888
+ // Always use secure cookies for auth
5889
+ sameSite,
5890
+ // 30 days default max age
5891
+ maxAge: 30 * 24 * 60 * 60
5892
+ }),
5893
+ storagePrefix: tokenCookie
5894
+ });
5895
+ }
5896
+ function createServerClient(token, baseURL) {
5897
+ return new SsoClient({
5898
+ baseURL,
5899
+ token
5900
+ // Initial token for server-side use
5901
+ });
5902
+ }
5872
5903
 
5873
- export { auth, authMiddleware, currentUser, getToken };
5904
+ export { auth, authMiddleware, createAuthOSClient, createServerClient, currentUser, getToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drmhse/authos-react",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "React and Next.js adapter for AuthOS authentication",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -35,7 +35,6 @@
35
35
  "dev": "tsup --watch",
36
36
  "typecheck": "tsc --noEmit",
37
37
  "lint": "eslint src --ext .ts,.tsx",
38
- "test:ct": "playwright test -c playwright-ct.config.ts --reporter=list",
39
38
  "prepublishOnly": "npm run build"
40
39
  },
41
40
  "keywords": [
@@ -53,8 +52,6 @@
53
52
  "react": ">=18.0.0"
54
53
  },
55
54
  "devDependencies": {
56
- "@playwright/experimental-ct-react": "^1.48.0",
57
- "@playwright/test": "^1.48.0",
58
55
  "@types/react": "^19.0.0",
59
56
  "next": "^15.1.0",
60
57
  "react": "^19.0.0",