@instroc/auth 1.3.0 → 2.0.0-alpha.1

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/dist/forms.d.ts CHANGED
@@ -1 +1 @@
1
- export { M as MessageOverrides, O as OnErrorResult, m as UseForgotPasswordFormOptions, n as UseForgotPasswordFormReturn, U as UseLoginFormOptions, h as UseLoginFormReturn, k as UseOtpFormOptions, l as UseOtpFormReturn, o as UseResetPasswordFormOptions, p as UseResetPasswordFormReturn, i as UseSignupFormOptions, j as UseSignupFormReturn, f as useForgotPasswordForm, u as useLoginForm, e as useOtpForm, g as useResetPasswordForm, d as useSignupForm } from './index-iglVgSQI.js';
1
+ export { M as MessageOverrides, O as OnErrorResult, m as UseForgotPasswordFormOptions, n as UseForgotPasswordFormReturn, U as UseLoginFormOptions, h as UseLoginFormReturn, k as UseOtpFormOptions, l as UseOtpFormReturn, o as UseResetPasswordFormOptions, p as UseResetPasswordFormReturn, i as UseSignupFormOptions, j as UseSignupFormReturn, f as useForgotPasswordForm, u as useLoginForm, e as useOtpForm, g as useResetPasswordForm, d as useSignupForm } from './index-BsFMnPty.js';
package/dist/forms.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  useOtpForm,
5
5
  useResetPasswordForm,
6
6
  useSignupForm
7
- } from "./chunk-WPSPVFVM.js";
7
+ } from "./chunk-L3F76GZD.js";
8
8
  export {
9
9
  useForgotPasswordForm,
10
10
  useLoginForm,
@@ -369,4 +369,4 @@ interface UseResetPasswordFormReturn {
369
369
  */
370
370
  declare function useResetPasswordForm(options: UseResetPasswordFormOptions): UseResetPasswordFormReturn;
371
371
 
372
- export { type AuthProviderProps as A, type LoginCredentials as L, type MessageOverrides as M, type OnErrorResult as O, type RefreshResponse as R, type SignupCredentials as S, type UseLoginFormOptions as U, type VisibilityConfig as V, type AuthContextValue as a, type AuthUser as b, type AuthSession as c, useSignupForm as d, useOtpForm as e, useForgotPasswordForm as f, useResetPasswordForm as g, type UseLoginFormReturn as h, type UseSignupFormOptions as i, type UseSignupFormReturn as j, type UseOtpFormOptions as k, type UseOtpFormReturn as l, type UseForgotPasswordFormOptions as m, type UseForgotPasswordFormReturn as n, type UseResetPasswordFormOptions as o, type UseResetPasswordFormReturn as p, type AuthState as q, type AuthConfig as r, type OAuthProvider as s, type SignupResult as t, useLoginForm as u, type UpdateProfileData as v, type AuthResponse as w };
372
+ export { type AuthContextValue as A, type LoginCredentials as L, type MessageOverrides as M, type OnErrorResult as O, type RefreshResponse as R, type SignupCredentials as S, type UseLoginFormOptions as U, type VisibilityConfig as V, type AuthUser as a, type AuthSession as b, type AuthProviderProps as c, useSignupForm as d, useOtpForm as e, useForgotPasswordForm as f, useResetPasswordForm as g, type UseLoginFormReturn as h, type UseSignupFormOptions as i, type UseSignupFormReturn as j, type UseOtpFormOptions as k, type UseOtpFormReturn as l, type UseForgotPasswordFormOptions as m, type UseForgotPasswordFormReturn as n, type UseResetPasswordFormOptions as o, type UseResetPasswordFormReturn as p, type AuthState as q, type AuthConfig as r, type OAuthProvider as s, type SignupResult as t, useLoginForm as u, type UpdateProfileData as v, type AuthResponse as w };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,21 @@
1
- import { A as AuthProviderProps, a as AuthContextValue, b as AuthUser, c as AuthSession } from './index-iglVgSQI.js';
2
- export { r as AuthConfig, w as AuthResponse, q as AuthState, L as LoginCredentials, M as MessageOverrides, s as OAuthProvider, O as OnErrorResult, R as RefreshResponse, S as SignupCredentials, t as SignupResult, v as UpdateProfileData, m as UseForgotPasswordFormOptions, n as UseForgotPasswordFormReturn, U as UseLoginFormOptions, h as UseLoginFormReturn, k as UseOtpFormOptions, l as UseOtpFormReturn, o as UseResetPasswordFormOptions, p as UseResetPasswordFormReturn, i as UseSignupFormOptions, j as UseSignupFormReturn, V as VisibilityConfig, f as useForgotPasswordForm, u as useLoginForm, e as useOtpForm, g as useResetPasswordForm, d as useSignupForm } from './index-iglVgSQI.js';
3
-
4
- declare function AuthProvider({ children, projectId: initialProjectId, baseUrl, persistSession, onAuthStateChange, }: AuthProviderProps): JSX.Element;
5
- declare function useAuthContext(): AuthContextValue;
1
+ import { A as AuthContextValue, a as AuthUser, b as AuthSession, c as AuthProviderProps } from './index-BsFMnPty.js';
2
+ export { r as AuthConfig, w as AuthResponse, q as AuthState, L as LoginCredentials, M as MessageOverrides, s as OAuthProvider, O as OnErrorResult, R as RefreshResponse, S as SignupCredentials, t as SignupResult, v as UpdateProfileData, m as UseForgotPasswordFormOptions, n as UseForgotPasswordFormReturn, U as UseLoginFormOptions, h as UseLoginFormReturn, k as UseOtpFormOptions, l as UseOtpFormReturn, o as UseResetPasswordFormOptions, p as UseResetPasswordFormReturn, i as UseSignupFormOptions, j as UseSignupFormReturn, V as VisibilityConfig, f as useForgotPasswordForm, u as useLoginForm, e as useOtpForm, g as useResetPasswordForm, d as useSignupForm } from './index-BsFMnPty.js';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
6
4
 
5
+ /**
6
+ * Primary auth hook. Reads state from the singleton auth store, returns
7
+ * imperative actions bound to the current config. Safe to call from any
8
+ * component depth — no provider tree required.
9
+ *
10
+ * `useAuthContext` is preserved as a legacy alias so existing generated
11
+ * code (`const { user } = useAuthContext()`) keeps working.
12
+ */
7
13
  declare function useAuth(): AuthContextValue;
14
+ /**
15
+ * Legacy alias — pre-v2 generated code uses `useAuthContext` and we keep
16
+ * it indefinitely so nothing breaks. New code should use `useAuth()`.
17
+ */
18
+ declare const useAuthContext: typeof useAuth;
8
19
  declare function useUser(): {
9
20
  user: AuthUser | null;
10
21
  loading: boolean;
@@ -34,12 +45,6 @@ declare function useAuthRequired(): {
34
45
  * Returns `false` while loading or when unauthenticated.
35
46
  */
36
47
  declare function useIsOwner(): boolean;
37
- /**
38
- * Minimal JWT payload decoder — no signature check (the server already
39
- * verified it). Returns undefined if the token is malformed. We only read
40
- * the `is_owner` boolean claim, which the BaaS auth signer sets from
41
- * `_users.is_owner`.
42
- */
43
48
  /**
44
49
  * Returns true if the current visitor is a member of the Instroc workspace
45
50
  * that owns this published app. Used by premium templates to gate owner-only
@@ -57,10 +62,11 @@ declare function useIsOwner(): boolean;
57
62
  * cookie is what the privacy gate uses to allow workspace members into
58
63
  * private apps.
59
64
  *
60
- * Dev/preview note: when running on `localhost`, `*.fly.dev`, or
61
- * `*.workers.dev` (dev-session HMR, editor preview), the hook returns `true`
62
- * so template authors can see admin UI while building. In production
63
- * (`*.instroc.app` and custom domains) the server answer is authoritative.
65
+ * Dev/preview note: when running on `localhost`, `*.fly.dev`, `*.workers.dev`,
66
+ * or `preview.instroc.app` (dev-session HMR, editor preview iframe, published
67
+ * preview snapshots), the hook returns `true` so template authors can see
68
+ * admin UI while building. In production (`*.instroc.app` subdomains and
69
+ * custom domains) the server answer is authoritative.
64
70
  */
65
71
  declare function useIsWorkspaceMember(): boolean;
66
72
 
@@ -95,4 +101,24 @@ declare class AuthError extends Error {
95
101
  constructor(message: string, status: number, code?: string);
96
102
  }
97
103
 
104
+ /**
105
+ * Legacy backward-compat shim for v1's `<AuthProvider>`.
106
+ *
107
+ * v2 of the SDK is store-based — auth state lives in a module-level
108
+ * singleton, hooks read from it directly, and there's no required
109
+ * provider in the tree. This component is kept so existing generated
110
+ * apps that mount `<AuthProvider projectId="...">` keep working
111
+ * unchanged. Internally it just calls `initInstroc` with the props and
112
+ * subscribes the `onAuthStateChange` listener.
113
+ *
114
+ * New code should call `initInstroc({ projectId })` once in main.tsx
115
+ * and skip the wrapper entirely.
116
+ *
117
+ * This shim is intentionally minimal — no React state, no useCallback
118
+ * gymnastics. The whole provider exists only so old generated main.tsx
119
+ * files don't crash with "AuthProvider is not a function" after the
120
+ * v2 upgrade.
121
+ */
122
+ declare function AuthProvider({ children, projectId, baseUrl, persistSession, onAuthStateChange, }: AuthProviderProps): react_jsx_runtime.JSX.Element;
123
+
98
124
  export { AuthContextValue, AuthError, AuthProvider, AuthProviderProps, AuthSession, AuthUser, useAuth, useAuthContext, useAuthRequired, useIsOwner, useIsWorkspaceMember, useSession, useUser };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  AuthError,
3
- AuthProvider,
3
+ ensureAuthBootstrap,
4
+ subscribeAuthStateChange,
4
5
  useAuth,
5
6
  useAuthContext,
6
7
  useAuthRequired,
@@ -13,7 +14,40 @@ import {
13
14
  useSession,
14
15
  useSignupForm,
15
16
  useUser
16
- } from "./chunk-WPSPVFVM.js";
17
+ } from "./chunk-L3F76GZD.js";
18
+
19
+ // src/provider.tsx
20
+ import { useEffect } from "react";
21
+ import { initInstroc, setInstrocProjectId } from "@instroc/client";
22
+ import { Fragment, jsx } from "react/jsx-runtime";
23
+ function AuthProvider({
24
+ children,
25
+ projectId,
26
+ baseUrl,
27
+ persistSession,
28
+ onAuthStateChange
29
+ }) {
30
+ if (projectId) {
31
+ initInstroc({
32
+ projectId,
33
+ ...baseUrl !== void 0 ? { baseUrl } : {},
34
+ ...persistSession !== void 0 ? { persistSession } : {}
35
+ });
36
+ }
37
+ ensureAuthBootstrap();
38
+ useEffect(() => {
39
+ if (projectId) {
40
+ setInstrocProjectId(projectId);
41
+ }
42
+ }, [projectId]);
43
+ useEffect(() => {
44
+ if (!onAuthStateChange)
45
+ return;
46
+ const unsub = subscribeAuthStateChange(onAuthStateChange);
47
+ return unsub;
48
+ }, [onAuthStateChange]);
49
+ return /* @__PURE__ */ jsx(Fragment, { children });
50
+ }
17
51
  export {
18
52
  AuthError,
19
53
  AuthProvider,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@instroc/auth",
3
- "version": "1.3.0",
4
- "description": "Authentication hooks for Instroc Cloud — useAuth, useUser, AuthProvider, and headless form hooks",
3
+ "version": "2.0.0-alpha.1",
4
+ "description": "Authentication hooks for Instroc Cloud — store-based useAuth/useUser with backward-compatible AuthProvider shim",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -23,11 +23,12 @@
23
23
  "dev": "tsup --watch"
24
24
  },
25
25
  "peerDependencies": {
26
- "react": "^18.0.0"
26
+ "react": "^18.0.0 || ^19.0.0"
27
+ },
28
+ "dependencies": {
29
+ "@instroc/client": "workspace:*"
27
30
  },
28
31
  "devDependencies": {
29
- "react": "^18.2.0",
30
- "@types/react": "^18.2.0",
31
32
  "tsup": "^8.0.0",
32
33
  "typescript": "^5.3.0"
33
34
  },