@contentgrowth/content-auth 0.2.1 → 0.2.3

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.
@@ -1074,6 +1074,15 @@ declare namespace schema {
1074
1074
  declare function getInvitationLink(data: any, baseUrl: string): {
1075
1075
  link: any;
1076
1076
  };
1077
+ /**
1078
+ * Extracts the session token from the request.
1079
+ * Checks "Authorization: Bearer <token>" header first.
1080
+ * Then checks cookies for "better-auth.session_token", "session_token", and "__Secure-better-auth.session_token".
1081
+ *
1082
+ * @param req The Request object
1083
+ * @returns The session token or null if not found
1084
+ */
1085
+ declare function getSessionToken(req: Request): string | null;
1077
1086
 
1078
1087
  interface AuthConfig {
1079
1088
  /**
@@ -1104,4 +1113,4 @@ declare const createAuthApp: (config: AuthConfig) => {
1104
1113
  auth: better_auth.Auth<any>;
1105
1114
  };
1106
1115
 
1107
- export { type AuthConfig, authMiddleware, createAuth, createAuthApp, getInvitationLink, schema };
1116
+ export { type AuthConfig, authMiddleware, createAuth, createAuthApp, getInvitationLink, getSessionToken, schema };
@@ -4,8 +4,9 @@ import {
4
4
  createAuth,
5
5
  createAuthApp,
6
6
  getInvitationLink,
7
+ getSessionToken,
7
8
  schema_exports
8
- } from "../chunk-FYU2PONS.js";
9
+ } from "../chunk-6DFIEMYG.js";
9
10
  import "../chunk-R5U7XKVJ.js";
10
11
  export {
11
12
  Hono,
@@ -13,5 +14,6 @@ export {
13
14
  createAuth,
14
15
  createAuthApp,
15
16
  getInvitationLink,
17
+ getSessionToken,
16
18
  schema_exports as schema
17
19
  };
@@ -16,10 +16,12 @@ var AuthForm = ({
16
16
  layout = "default",
17
17
  socialPosition = "top",
18
18
  view,
19
- onSwitchMode
19
+ onSwitchMode,
20
+ defaultEmail = "",
21
+ lockEmail = false
20
22
  }) => {
21
23
  const [isLogin, setIsLogin] = useState(view !== "signup");
22
- const [email, setEmail] = useState("");
24
+ const [email, setEmail] = useState(defaultEmail);
23
25
  const [password, setPassword] = useState("");
24
26
  const [name, setName] = useState("");
25
27
  const [loading, setLoading] = useState(false);
@@ -73,26 +75,29 @@ var AuthForm = ({
73
75
  else if (width === "wide") widthClass = "ca-width-wide";
74
76
  else widthClass = "ca-width-default";
75
77
  const containerClass = `ca-container ${layout === "split" ? "ca-layout-split" : ""} ${widthClass} ${className || ""}`;
76
- const renderSocials = () => socialProviders.length > 0 && /* @__PURE__ */ jsx("div", { className: socialClass, children: socialProviders.map((provider) => /* @__PURE__ */ jsxs(
77
- "button",
78
- {
79
- type: "button",
80
- className: `ca-button ca-button-social ca-button-${provider}`,
81
- onClick: () => handleSocialLogin(provider),
82
- disabled: loading,
83
- children: [
84
- provider === "google" && /* @__PURE__ */ jsx("svg", { className: "ca-icon", viewBox: "0 0 24 24", width: "20", height: "20", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxs("g", { transform: "matrix(1, 0, 0, 1, 27.009001, -39.238998)", children: [
85
- /* @__PURE__ */ jsx("path", { fill: "#4285F4", d: "M -3.264 51.509 C -3.264 50.719 -3.334 49.969 -3.454 49.239 L -14.754 49.239 L -14.754 53.749 L -8.284 53.749 C -8.574 55.229 -9.424 56.479 -10.684 57.329 L -10.684 60.329 L -6.824 60.329 C -4.564 58.239 -3.264 55.159 -3.264 51.509 Z" }),
86
- /* @__PURE__ */ jsx("path", { fill: "#34A853", d: "M -14.754 63.239 C -11.514 63.239 -8.804 62.159 -6.824 60.329 L -10.684 57.329 C -11.764 58.049 -13.134 58.489 -14.754 58.489 C -17.884 58.489 -20.534 56.379 -21.484 53.529 L -25.464 53.529 L -25.464 56.619 C -23.494 60.539 -19.444 63.239 -14.754 63.239 Z" }),
87
- /* @__PURE__ */ jsx("path", { fill: "#FBBC05", d: "M -21.484 53.529 C -21.734 52.809 -21.864 52.039 -21.864 51.239 C -21.864 50.439 -21.734 49.669 -21.484 48.949 L -21.484 45.859 L -25.464 45.859 C -26.284 47.479 -26.754 49.299 -26.754 51.239 C -26.754 53.179 -26.284 54.999 -25.464 56.619 L -21.484 53.529 Z" }),
88
- /* @__PURE__ */ jsx("path", { fill: "#EA4335", d: "M -14.754 43.989 C -12.984 43.989 -11.424 44.599 -10.174 45.789 L -6.744 42.359 C -8.804 40.429 -11.514 39.239 -14.754 39.239 C -19.444 39.239 -23.494 41.939 -25.464 45.859 L -21.484 48.949 C -20.534 46.099 -17.884 43.989 -14.754 43.989 Z" })
89
- ] }) }),
90
- provider === "github" && /* @__PURE__ */ jsx("svg", { className: "ca-icon", viewBox: "0 0 24 24", width: "20", height: "20", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M12 2C6.477 2 2 6.477 2 12c0 4.42 2.865 8.17 6.839 9.49.5.092.682-.217.682-.482 0-.237-.008-.866-.013-1.7-2.782.604-3.369-1.34-3.369-1.34-.454-1.156-1.11-1.464-1.11-1.464-.908-.62.069-.608.069-.608 1.003.07 1.531 1.03 1.531 1.03.892 1.529 2.341 1.087 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.11-4.555-4.943 0-1.091.39-1.984 1.029-2.683-.103-.253-.446-1.27.098-2.647 0 0 .84-.269 2.75 1.026A9.564 9.564 0 0 1 12 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.699 1.028 1.592 1.028 2.683 0 3.842-2.339 4.687-4.566 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0 0 22 12c0-5.523-4.477-10-10-10z", fill: "currentColor" }) }),
91
- /* @__PURE__ */ jsx("span", { className: "ca-btn-text", children: provider === "github" ? "GitHub" : "Google" })
92
- ]
93
- },
94
- provider
95
- )) });
78
+ const renderSocials = () => (
79
+ // Hide social logins when email is locked (e.g., invitation flow)
80
+ !lockEmail && socialProviders.length > 0 && /* @__PURE__ */ jsx("div", { className: socialClass, children: socialProviders.map((provider) => /* @__PURE__ */ jsxs(
81
+ "button",
82
+ {
83
+ type: "button",
84
+ className: `ca-button ca-button-social ca-button-${provider}`,
85
+ onClick: () => handleSocialLogin(provider),
86
+ disabled: loading,
87
+ children: [
88
+ provider === "google" && /* @__PURE__ */ jsx("svg", { className: "ca-icon", viewBox: "0 0 24 24", width: "20", height: "20", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxs("g", { transform: "matrix(1, 0, 0, 1, 27.009001, -39.238998)", children: [
89
+ /* @__PURE__ */ jsx("path", { fill: "#4285F4", d: "M -3.264 51.509 C -3.264 50.719 -3.334 49.969 -3.454 49.239 L -14.754 49.239 L -14.754 53.749 L -8.284 53.749 C -8.574 55.229 -9.424 56.479 -10.684 57.329 L -10.684 60.329 L -6.824 60.329 C -4.564 58.239 -3.264 55.159 -3.264 51.509 Z" }),
90
+ /* @__PURE__ */ jsx("path", { fill: "#34A853", d: "M -14.754 63.239 C -11.514 63.239 -8.804 62.159 -6.824 60.329 L -10.684 57.329 C -11.764 58.049 -13.134 58.489 -14.754 58.489 C -17.884 58.489 -20.534 56.379 -21.484 53.529 L -25.464 53.529 L -25.464 56.619 C -23.494 60.539 -19.444 63.239 -14.754 63.239 Z" }),
91
+ /* @__PURE__ */ jsx("path", { fill: "#FBBC05", d: "M -21.484 53.529 C -21.734 52.809 -21.864 52.039 -21.864 51.239 C -21.864 50.439 -21.734 49.669 -21.484 48.949 L -21.484 45.859 L -25.464 45.859 C -26.284 47.479 -26.754 49.299 -26.754 51.239 C -26.754 53.179 -26.284 54.999 -25.464 56.619 L -21.484 53.529 Z" }),
92
+ /* @__PURE__ */ jsx("path", { fill: "#EA4335", d: "M -14.754 43.989 C -12.984 43.989 -11.424 44.599 -10.174 45.789 L -6.744 42.359 C -8.804 40.429 -11.514 39.239 -14.754 39.239 C -19.444 39.239 -23.494 41.939 -25.464 45.859 L -21.484 48.949 C -20.534 46.099 -17.884 43.989 -14.754 43.989 Z" })
93
+ ] }) }),
94
+ provider === "github" && /* @__PURE__ */ jsx("svg", { className: "ca-icon", viewBox: "0 0 24 24", width: "20", height: "20", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M12 2C6.477 2 2 6.477 2 12c0 4.42 2.865 8.17 6.839 9.49.5.092.682-.217.682-.482 0-.237-.008-.866-.013-1.7-2.782.604-3.369-1.34-3.369-1.34-.454-1.156-1.11-1.464-1.11-1.464-.908-.62.069-.608.069-.608 1.003.07 1.531 1.03 1.531 1.03.892 1.529 2.341 1.087 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.11-4.555-4.943 0-1.091.39-1.984 1.029-2.683-.103-.253-.446-1.27.098-2.647 0 0 .84-.269 2.75 1.026A9.564 9.564 0 0 1 12 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.699 1.028 1.592 1.028 2.683 0 3.842-2.339 4.687-4.566 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0 0 22 12c0-5.523-4.477-10-10-10z", fill: "currentColor" }) }),
95
+ /* @__PURE__ */ jsx("span", { className: "ca-btn-text", children: provider === "github" ? "GitHub" : "Google" })
96
+ ]
97
+ },
98
+ provider
99
+ )) })
100
+ );
96
101
  const renderForm = () => {
97
102
  if (!mounted) {
98
103
  return /* @__PURE__ */ jsx("div", { className: "ca-form", children: /* @__PURE__ */ jsxs("div", { className: "ca-input-group", style: { opacity: 0 }, children: [
@@ -122,9 +127,10 @@ var AuthForm = ({
122
127
  {
123
128
  id: "email",
124
129
  type: "email",
125
- className: "ca-input",
130
+ className: `ca-input ${lockEmail ? "ca-input-locked" : ""}`,
126
131
  value: email,
127
- onChange: (e) => setEmail(e.target.value),
132
+ onChange: (e) => !lockEmail && setEmail(e.target.value),
133
+ readOnly: lockEmail,
128
134
  required: true
129
135
  }
130
136
  )
@@ -175,6 +175,22 @@ function getInvitationLink(data, baseUrl) {
175
175
  link: rawLink
176
176
  };
177
177
  }
178
+ function getSessionToken(req) {
179
+ const authHeader = req.headers.get("Authorization");
180
+ if (authHeader?.startsWith("Bearer ")) {
181
+ return authHeader.split(" ")[1];
182
+ }
183
+ const cookieHeader = req.headers.get("Cookie");
184
+ if (!cookieHeader) return null;
185
+ const cookies = {};
186
+ cookieHeader.split(";").forEach((c) => {
187
+ const [key, value] = c.trim().split("=");
188
+ if (key && value) {
189
+ cookies[key] = value;
190
+ }
191
+ });
192
+ return cookies["better-auth.session_token"] || cookies["session_token"] || cookies["__Secure-better-auth.session_token"] || null;
193
+ }
178
194
 
179
195
  // src/backend/index.ts
180
196
  var createAuth = (config) => {
@@ -235,6 +251,7 @@ var createAuthApp = (config) => {
235
251
  export {
236
252
  schema_exports,
237
253
  getInvitationLink,
254
+ getSessionToken,
238
255
  Hono,
239
256
  createAuth,
240
257
  authMiddleware,
@@ -628,7 +628,7 @@ declare const createClient: (baseUrl?: string) => {
628
628
  sortDirection?: "asc" | "desc" | undefined;
629
629
  filterField?: string | undefined;
630
630
  filterValue?: string | number | boolean | undefined;
631
- filterOperator?: "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "contains" | undefined;
631
+ filterOperator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "contains" | undefined;
632
632
  organizationId?: string | undefined;
633
633
  organizationSlug?: string | undefined;
634
634
  }> & Record<string, any>, Record<string, any> | undefined>>(data_0?: better_auth.Prettify<{
@@ -639,7 +639,7 @@ declare const createClient: (baseUrl?: string) => {
639
639
  sortDirection?: "asc" | "desc" | undefined;
640
640
  filterField?: string | undefined;
641
641
  filterValue?: string | number | boolean | undefined;
642
- filterOperator?: "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "contains" | undefined;
642
+ filterOperator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "contains" | undefined;
643
643
  organizationId?: string | undefined;
644
644
  organizationSlug?: string | undefined;
645
645
  } | undefined;
@@ -746,7 +746,7 @@ declare const createClient: (baseUrl?: string) => {
746
746
  } & {
747
747
  signIn: {
748
748
  social: <FetchOptions extends better_auth.ClientFetchOption<Partial<{
749
- provider: (string & {}) | "linear" | "huggingface" | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
749
+ provider: (string & {}) | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
750
750
  callbackURL?: string | undefined;
751
751
  newUserCallbackURL?: string | undefined;
752
752
  errorCallbackURL?: string | undefined;
@@ -763,7 +763,7 @@ declare const createClient: (baseUrl?: string) => {
763
763
  loginHint?: string | undefined;
764
764
  additionalData?: Record<string, any> | undefined;
765
765
  }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth.Prettify<{
766
- provider: (string & {}) | "linear" | "huggingface" | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
766
+ provider: (string & {}) | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
767
767
  callbackURL?: string | undefined;
768
768
  newUserCallbackURL?: string | undefined;
769
769
  errorCallbackURL?: string | undefined;
@@ -2205,7 +2205,7 @@ declare const authClient: {
2205
2205
  sortDirection?: "asc" | "desc" | undefined;
2206
2206
  filterField?: string | undefined;
2207
2207
  filterValue?: string | number | boolean | undefined;
2208
- filterOperator?: "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "contains" | undefined;
2208
+ filterOperator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "contains" | undefined;
2209
2209
  organizationId?: string | undefined;
2210
2210
  organizationSlug?: string | undefined;
2211
2211
  }> & Record<string, any>, Record<string, any> | undefined>>(data_0?: better_auth.Prettify<{
@@ -2216,7 +2216,7 @@ declare const authClient: {
2216
2216
  sortDirection?: "asc" | "desc" | undefined;
2217
2217
  filterField?: string | undefined;
2218
2218
  filterValue?: string | number | boolean | undefined;
2219
- filterOperator?: "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "contains" | undefined;
2219
+ filterOperator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "contains" | undefined;
2220
2220
  organizationId?: string | undefined;
2221
2221
  organizationSlug?: string | undefined;
2222
2222
  } | undefined;
@@ -2323,7 +2323,7 @@ declare const authClient: {
2323
2323
  } & {
2324
2324
  signIn: {
2325
2325
  social: <FetchOptions extends better_auth.ClientFetchOption<Partial<{
2326
- provider: (string & {}) | "linear" | "huggingface" | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
2326
+ provider: (string & {}) | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
2327
2327
  callbackURL?: string | undefined;
2328
2328
  newUserCallbackURL?: string | undefined;
2329
2329
  errorCallbackURL?: string | undefined;
@@ -2340,7 +2340,7 @@ declare const authClient: {
2340
2340
  loginHint?: string | undefined;
2341
2341
  additionalData?: Record<string, any> | undefined;
2342
2342
  }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth.Prettify<{
2343
- provider: (string & {}) | "linear" | "huggingface" | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
2343
+ provider: (string & {}) | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
2344
2344
  callbackURL?: string | undefined;
2345
2345
  newUserCallbackURL?: string | undefined;
2346
2346
  errorCallbackURL?: string | undefined;
@@ -18,6 +18,10 @@ interface AuthFormProps {
18
18
  layout?: 'default' | 'split';
19
19
  socialPosition?: 'top' | 'bottom';
20
20
  onSwitchMode?: () => void;
21
+ /** Pre-populate the email field (useful for invitation flows) */
22
+ defaultEmail?: string;
23
+ /** Lock the email field (readonly) and hide social logins */
24
+ lockEmail?: boolean;
21
25
  }
22
26
  declare const AuthForm: React.FC<AuthFormProps>;
23
27
 
@@ -3,7 +3,7 @@ import {
3
3
  CreateOrganizationForm,
4
4
  InviteMemberForm,
5
5
  OrganizationSwitcher
6
- } from "../chunk-VX6RJ5XJ.js";
6
+ } from "../chunk-2TPT2QM4.js";
7
7
  import {
8
8
  authClient,
9
9
  createClient
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AuthConfig, authMiddleware, createAuth, createAuthApp, getInvitationLink, schema } from './backend/index.js';
1
+ export { AuthConfig, authMiddleware, createAuth, createAuthApp, getInvitationLink, getSessionToken, schema } from './backend/index.js';
2
2
  export { AuthForm, CreateOrganizationForm, InviteMemberForm, OrganizationSwitcher } from './frontend/index.js';
3
3
  export { authClient, createClient } from './frontend/client.js';
4
4
  export * from 'better-auth';
package/dist/index.js CHANGED
@@ -4,14 +4,15 @@ import {
4
4
  createAuth,
5
5
  createAuthApp,
6
6
  getInvitationLink,
7
+ getSessionToken,
7
8
  schema_exports
8
- } from "./chunk-FYU2PONS.js";
9
+ } from "./chunk-6DFIEMYG.js";
9
10
  import {
10
11
  AuthForm,
11
12
  CreateOrganizationForm,
12
13
  InviteMemberForm,
13
14
  OrganizationSwitcher
14
- } from "./chunk-VX6RJ5XJ.js";
15
+ } from "./chunk-2TPT2QM4.js";
15
16
  import {
16
17
  authClient,
17
18
  createClient
@@ -29,5 +30,6 @@ export {
29
30
  createAuthApp,
30
31
  createClient,
31
32
  getInvitationLink,
33
+ getSessionToken,
32
34
  schema_exports as schema
33
35
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentgrowth/content-auth",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Better Auth wrapper with UI components for Cloudflare Workers & Pages",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",