@githat/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.
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @githat/nextjs/server
3
+ *
4
+ * Server-side utilities for token verification in Next.js API routes and middleware.
5
+ * This module runs on the server only — do not import in client components.
6
+ */
7
+ interface AuthPayload {
8
+ userId: string;
9
+ email: string;
10
+ orgId: string | null;
11
+ orgSlug: string | null;
12
+ role: 'owner' | 'admin' | 'member' | null;
13
+ tier: 'free' | 'basic' | 'pro' | 'enterprise' | null;
14
+ }
15
+ interface VerifyOptions {
16
+ /**
17
+ * Secret key for local JWT verification. If provided, tokens are verified
18
+ * locally without making an API call (~1ms vs ~50-100ms).
19
+ * Must match the JWT_SECRET used by the GitHat backend.
20
+ */
21
+ secretKey?: string;
22
+ /**
23
+ * API URL for remote token verification. Defaults to https://api.githat.io
24
+ */
25
+ apiUrl?: string;
26
+ }
27
+ interface OrgMetadata {
28
+ [key: string]: unknown;
29
+ }
30
+ declare const COOKIE_NAMES: {
31
+ readonly accessToken: "githat_access";
32
+ readonly refreshToken: "githat_refresh";
33
+ };
34
+ /**
35
+ * Verify a JWT token and return the decoded auth payload.
36
+ *
37
+ * Supports two verification modes:
38
+ * 1. Local verification (recommended for performance): Pass `secretKey` option
39
+ * 2. API-based verification: No secret key needed, calls api.githat.io/auth/verify
40
+ *
41
+ * @example Local verification (fast, ~1ms)
42
+ * ```ts
43
+ * const auth = await verifyToken(token, {
44
+ * secretKey: process.env.GITHAT_SECRET_KEY
45
+ * });
46
+ * ```
47
+ *
48
+ * @example API-based verification (simpler setup)
49
+ * ```ts
50
+ * const auth = await verifyToken(token);
51
+ * ```
52
+ */
53
+ declare function verifyToken(token: string, options?: VerifyOptions): Promise<AuthPayload>;
54
+ /**
55
+ * Extract and verify the auth token from a Next.js request.
56
+ * Checks cookies first (for httpOnly cookie mode), then Authorization header.
57
+ *
58
+ * Returns null if no token is found (unauthenticated request).
59
+ * Throws if a token is found but is invalid/expired.
60
+ *
61
+ * @example In a Next.js API route
62
+ * ```ts
63
+ * import { getAuth } from '@githat/nextjs/server';
64
+ *
65
+ * export async function GET(request: Request) {
66
+ * const auth = await getAuth(request, {
67
+ * secretKey: process.env.GITHAT_SECRET_KEY
68
+ * });
69
+ *
70
+ * if (!auth) {
71
+ * return Response.json({ error: 'Unauthorized' }, { status: 401 });
72
+ * }
73
+ *
74
+ * return Response.json({ userId: auth.userId });
75
+ * }
76
+ * ```
77
+ */
78
+ declare function getAuth(request: Request, options?: VerifyOptions): Promise<AuthPayload | null>;
79
+ /**
80
+ * Get organization metadata from the server.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { getOrgMetadata } from '@githat/nextjs/server';
85
+ *
86
+ * const meta = await getOrgMetadata(orgId, {
87
+ * token: accessToken,
88
+ * apiUrl: 'https://api.githat.io'
89
+ * });
90
+ * console.log(meta.stripeAccountId);
91
+ * ```
92
+ */
93
+ declare function getOrgMetadata(orgId: string, options: {
94
+ token: string;
95
+ apiUrl?: string;
96
+ }): Promise<OrgMetadata>;
97
+ /**
98
+ * Update organization metadata from the server.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * import { updateOrgMetadata } from '@githat/nextjs/server';
103
+ *
104
+ * await updateOrgMetadata(orgId, { stripeAccountId: 'acct_xxx' }, {
105
+ * token: accessToken,
106
+ * apiUrl: 'https://api.githat.io'
107
+ * });
108
+ * ```
109
+ */
110
+ declare function updateOrgMetadata(orgId: string, metadata: OrgMetadata, options: {
111
+ token: string;
112
+ apiUrl?: string;
113
+ }): Promise<OrgMetadata>;
114
+
115
+ export { type AuthPayload, COOKIE_NAMES, type OrgMetadata, type VerifyOptions, getAuth, getOrgMetadata, updateOrgMetadata, verifyToken };
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @githat/nextjs/server
3
+ *
4
+ * Server-side utilities for token verification in Next.js API routes and middleware.
5
+ * This module runs on the server only — do not import in client components.
6
+ */
7
+ interface AuthPayload {
8
+ userId: string;
9
+ email: string;
10
+ orgId: string | null;
11
+ orgSlug: string | null;
12
+ role: 'owner' | 'admin' | 'member' | null;
13
+ tier: 'free' | 'basic' | 'pro' | 'enterprise' | null;
14
+ }
15
+ interface VerifyOptions {
16
+ /**
17
+ * Secret key for local JWT verification. If provided, tokens are verified
18
+ * locally without making an API call (~1ms vs ~50-100ms).
19
+ * Must match the JWT_SECRET used by the GitHat backend.
20
+ */
21
+ secretKey?: string;
22
+ /**
23
+ * API URL for remote token verification. Defaults to https://api.githat.io
24
+ */
25
+ apiUrl?: string;
26
+ }
27
+ interface OrgMetadata {
28
+ [key: string]: unknown;
29
+ }
30
+ declare const COOKIE_NAMES: {
31
+ readonly accessToken: "githat_access";
32
+ readonly refreshToken: "githat_refresh";
33
+ };
34
+ /**
35
+ * Verify a JWT token and return the decoded auth payload.
36
+ *
37
+ * Supports two verification modes:
38
+ * 1. Local verification (recommended for performance): Pass `secretKey` option
39
+ * 2. API-based verification: No secret key needed, calls api.githat.io/auth/verify
40
+ *
41
+ * @example Local verification (fast, ~1ms)
42
+ * ```ts
43
+ * const auth = await verifyToken(token, {
44
+ * secretKey: process.env.GITHAT_SECRET_KEY
45
+ * });
46
+ * ```
47
+ *
48
+ * @example API-based verification (simpler setup)
49
+ * ```ts
50
+ * const auth = await verifyToken(token);
51
+ * ```
52
+ */
53
+ declare function verifyToken(token: string, options?: VerifyOptions): Promise<AuthPayload>;
54
+ /**
55
+ * Extract and verify the auth token from a Next.js request.
56
+ * Checks cookies first (for httpOnly cookie mode), then Authorization header.
57
+ *
58
+ * Returns null if no token is found (unauthenticated request).
59
+ * Throws if a token is found but is invalid/expired.
60
+ *
61
+ * @example In a Next.js API route
62
+ * ```ts
63
+ * import { getAuth } from '@githat/nextjs/server';
64
+ *
65
+ * export async function GET(request: Request) {
66
+ * const auth = await getAuth(request, {
67
+ * secretKey: process.env.GITHAT_SECRET_KEY
68
+ * });
69
+ *
70
+ * if (!auth) {
71
+ * return Response.json({ error: 'Unauthorized' }, { status: 401 });
72
+ * }
73
+ *
74
+ * return Response.json({ userId: auth.userId });
75
+ * }
76
+ * ```
77
+ */
78
+ declare function getAuth(request: Request, options?: VerifyOptions): Promise<AuthPayload | null>;
79
+ /**
80
+ * Get organization metadata from the server.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { getOrgMetadata } from '@githat/nextjs/server';
85
+ *
86
+ * const meta = await getOrgMetadata(orgId, {
87
+ * token: accessToken,
88
+ * apiUrl: 'https://api.githat.io'
89
+ * });
90
+ * console.log(meta.stripeAccountId);
91
+ * ```
92
+ */
93
+ declare function getOrgMetadata(orgId: string, options: {
94
+ token: string;
95
+ apiUrl?: string;
96
+ }): Promise<OrgMetadata>;
97
+ /**
98
+ * Update organization metadata from the server.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * import { updateOrgMetadata } from '@githat/nextjs/server';
103
+ *
104
+ * await updateOrgMetadata(orgId, { stripeAccountId: 'acct_xxx' }, {
105
+ * token: accessToken,
106
+ * apiUrl: 'https://api.githat.io'
107
+ * });
108
+ * ```
109
+ */
110
+ declare function updateOrgMetadata(orgId: string, metadata: OrgMetadata, options: {
111
+ token: string;
112
+ apiUrl?: string;
113
+ }): Promise<OrgMetadata>;
114
+
115
+ export { type AuthPayload, COOKIE_NAMES, type OrgMetadata, type VerifyOptions, getAuth, getOrgMetadata, updateOrgMetadata, verifyToken };
package/dist/server.js ADDED
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/server.ts
31
+ var server_exports = {};
32
+ __export(server_exports, {
33
+ COOKIE_NAMES: () => COOKIE_NAMES,
34
+ getAuth: () => getAuth,
35
+ getOrgMetadata: () => getOrgMetadata,
36
+ updateOrgMetadata: () => updateOrgMetadata,
37
+ verifyToken: () => verifyToken
38
+ });
39
+ module.exports = __toCommonJS(server_exports);
40
+ var jose = __toESM(require("jose"));
41
+
42
+ // src/config.ts
43
+ var DEFAULT_API_URL = "https://api.githat.io";
44
+
45
+ // src/server.ts
46
+ var COOKIE_NAMES = {
47
+ accessToken: "githat_access",
48
+ refreshToken: "githat_refresh"
49
+ };
50
+ async function verifyToken(token, options = {}) {
51
+ const { secretKey, apiUrl = DEFAULT_API_URL } = options;
52
+ if (secretKey) {
53
+ return verifyTokenLocally(token, secretKey);
54
+ }
55
+ return verifyTokenViaAPI(token, apiUrl);
56
+ }
57
+ async function verifyTokenLocally(token, secretKey) {
58
+ try {
59
+ const secret = new TextEncoder().encode(secretKey);
60
+ const { payload } = await jose.jwtVerify(token, secret, {
61
+ algorithms: ["HS256"]
62
+ });
63
+ if (payload.type && payload.type !== "user") {
64
+ throw new Error("Invalid token type");
65
+ }
66
+ if (payload.tokenType !== "access") {
67
+ throw new Error("Invalid token type");
68
+ }
69
+ return {
70
+ userId: payload.userId,
71
+ email: payload.email,
72
+ orgId: payload.orgId || null,
73
+ orgSlug: payload.orgSlug || null,
74
+ role: payload.orgRole || null,
75
+ tier: null
76
+ // Tier requires DB lookup, not available in local verification
77
+ };
78
+ } catch (err) {
79
+ if (err instanceof jose.errors.JWTExpired) {
80
+ throw new Error("Token expired");
81
+ }
82
+ if (err instanceof jose.errors.JWTClaimValidationFailed) {
83
+ throw new Error("Invalid token claims");
84
+ }
85
+ if (err instanceof jose.errors.JWTInvalid) {
86
+ throw new Error("Invalid token");
87
+ }
88
+ if (err instanceof jose.errors.JWSSignatureVerificationFailed) {
89
+ throw new Error("Invalid token signature");
90
+ }
91
+ throw err;
92
+ }
93
+ }
94
+ async function verifyTokenViaAPI(token, apiUrl) {
95
+ const response = await fetch(`${apiUrl}/auth/verify`, {
96
+ method: "GET",
97
+ headers: {
98
+ Authorization: `Bearer ${token}`,
99
+ "Content-Type": "application/json"
100
+ }
101
+ });
102
+ if (!response.ok) {
103
+ const data2 = await response.json().catch(() => ({}));
104
+ throw new Error(data2.error || "Token verification failed");
105
+ }
106
+ const data = await response.json();
107
+ return {
108
+ userId: data.userId,
109
+ email: data.email,
110
+ orgId: data.orgId,
111
+ orgSlug: data.orgSlug,
112
+ role: data.role,
113
+ tier: data.tier
114
+ };
115
+ }
116
+ async function getAuth(request, options = {}) {
117
+ const cookieHeader = request.headers.get("cookie");
118
+ let token = null;
119
+ if (cookieHeader) {
120
+ const cookies = parseCookies(cookieHeader);
121
+ token = cookies[COOKIE_NAMES.accessToken] || null;
122
+ }
123
+ if (!token) {
124
+ const authHeader = request.headers.get("authorization");
125
+ if (authHeader?.startsWith("Bearer ")) {
126
+ token = authHeader.slice(7);
127
+ }
128
+ }
129
+ if (!token) {
130
+ return null;
131
+ }
132
+ return verifyToken(token, options);
133
+ }
134
+ function parseCookies(cookieHeader) {
135
+ const cookies = {};
136
+ const pairs = cookieHeader.split(";");
137
+ for (const pair of pairs) {
138
+ const [name, ...rest] = pair.trim().split("=");
139
+ if (name) {
140
+ cookies[name] = rest.join("=");
141
+ }
142
+ }
143
+ return cookies;
144
+ }
145
+ async function getOrgMetadata(orgId, options) {
146
+ const { token, apiUrl = DEFAULT_API_URL } = options;
147
+ const response = await fetch(`${apiUrl}/orgs/${orgId}/metadata`, {
148
+ method: "GET",
149
+ headers: {
150
+ Authorization: `Bearer ${token}`,
151
+ "Content-Type": "application/json"
152
+ }
153
+ });
154
+ if (!response.ok) {
155
+ const data2 = await response.json().catch(() => ({}));
156
+ throw new Error(data2.error || "Failed to get org metadata");
157
+ }
158
+ const data = await response.json();
159
+ return data.metadata || {};
160
+ }
161
+ async function updateOrgMetadata(orgId, metadata, options) {
162
+ const { token, apiUrl = DEFAULT_API_URL } = options;
163
+ const response = await fetch(`${apiUrl}/orgs/${orgId}/metadata`, {
164
+ method: "PATCH",
165
+ headers: {
166
+ Authorization: `Bearer ${token}`,
167
+ "Content-Type": "application/json"
168
+ },
169
+ body: JSON.stringify(metadata)
170
+ });
171
+ if (!response.ok) {
172
+ const data2 = await response.json().catch(() => ({}));
173
+ throw new Error(data2.error || "Failed to update org metadata");
174
+ }
175
+ const data = await response.json();
176
+ return data.metadata || {};
177
+ }
178
+ // Annotate the CommonJS export names for ESM import in node:
179
+ 0 && (module.exports = {
180
+ COOKIE_NAMES,
181
+ getAuth,
182
+ getOrgMetadata,
183
+ updateOrgMetadata,
184
+ verifyToken
185
+ });
186
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server.ts","../src/config.ts"],"sourcesContent":["/**\n * @githat/nextjs/server\n *\n * Server-side utilities for token verification in Next.js API routes and middleware.\n * This module runs on the server only — do not import in client components.\n */\n\nimport * as jose from 'jose';\nimport { DEFAULT_API_URL } from './config';\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface AuthPayload {\n userId: string;\n email: string;\n orgId: string | null;\n orgSlug: string | null;\n role: 'owner' | 'admin' | 'member' | null;\n tier: 'free' | 'basic' | 'pro' | 'enterprise' | null;\n}\n\nexport interface VerifyOptions {\n /**\n * Secret key for local JWT verification. If provided, tokens are verified\n * locally without making an API call (~1ms vs ~50-100ms).\n * Must match the JWT_SECRET used by the GitHat backend.\n */\n secretKey?: string;\n\n /**\n * API URL for remote token verification. Defaults to https://api.githat.io\n */\n apiUrl?: string;\n}\n\nexport interface OrgMetadata {\n [key: string]: unknown;\n}\n\n// ============================================================================\n// Cookie Names\n// ============================================================================\n\nexport const COOKIE_NAMES = {\n accessToken: 'githat_access',\n refreshToken: 'githat_refresh',\n} as const;\n\n// ============================================================================\n// Token Verification\n// ============================================================================\n\n/**\n * Verify a JWT token and return the decoded auth payload.\n *\n * Supports two verification modes:\n * 1. Local verification (recommended for performance): Pass `secretKey` option\n * 2. API-based verification: No secret key needed, calls api.githat.io/auth/verify\n *\n * @example Local verification (fast, ~1ms)\n * ```ts\n * const auth = await verifyToken(token, {\n * secretKey: process.env.GITHAT_SECRET_KEY\n * });\n * ```\n *\n * @example API-based verification (simpler setup)\n * ```ts\n * const auth = await verifyToken(token);\n * ```\n */\nexport async function verifyToken(\n token: string,\n options: VerifyOptions = {}\n): Promise<AuthPayload> {\n const { secretKey, apiUrl = DEFAULT_API_URL } = options;\n\n if (secretKey) {\n // Local verification using jose\n return verifyTokenLocally(token, secretKey);\n }\n\n // API-based verification\n return verifyTokenViaAPI(token, apiUrl);\n}\n\n/**\n * Verify token locally using the secret key (no network call)\n */\nasync function verifyTokenLocally(\n token: string,\n secretKey: string\n): Promise<AuthPayload> {\n try {\n const secret = new TextEncoder().encode(secretKey);\n const { payload } = await jose.jwtVerify(token, secret, {\n algorithms: ['HS256'],\n });\n\n // Validate this is a user access token\n if (payload.type && payload.type !== 'user') {\n throw new Error('Invalid token type');\n }\n if (payload.tokenType !== 'access') {\n throw new Error('Invalid token type');\n }\n\n return {\n userId: payload.userId as string,\n email: payload.email as string,\n orgId: (payload.orgId as string) || null,\n orgSlug: (payload.orgSlug as string) || null,\n role: (payload.orgRole as AuthPayload['role']) || null,\n tier: null, // Tier requires DB lookup, not available in local verification\n };\n } catch (err) {\n if (err instanceof jose.errors.JWTExpired) {\n throw new Error('Token expired');\n }\n if (err instanceof jose.errors.JWTClaimValidationFailed) {\n throw new Error('Invalid token claims');\n }\n if (err instanceof jose.errors.JWTInvalid) {\n throw new Error('Invalid token');\n }\n // JWSSignatureVerificationFailed is used for invalid signatures\n if (err instanceof jose.errors.JWSSignatureVerificationFailed) {\n throw new Error('Invalid token signature');\n }\n throw err;\n }\n}\n\n/**\n * Verify token via API call to api.githat.io/auth/verify\n */\nasync function verifyTokenViaAPI(\n token: string,\n apiUrl: string\n): Promise<AuthPayload> {\n const response = await fetch(`${apiUrl}/auth/verify`, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n const data = await response.json().catch(() => ({}));\n throw new Error(data.error || 'Token verification failed');\n }\n\n const data = await response.json();\n return {\n userId: data.userId,\n email: data.email,\n orgId: data.orgId,\n orgSlug: data.orgSlug,\n role: data.role,\n tier: data.tier,\n };\n}\n\n// ============================================================================\n// Request Helpers\n// ============================================================================\n\n/**\n * Extract and verify the auth token from a Next.js request.\n * Checks cookies first (for httpOnly cookie mode), then Authorization header.\n *\n * Returns null if no token is found (unauthenticated request).\n * Throws if a token is found but is invalid/expired.\n *\n * @example In a Next.js API route\n * ```ts\n * import { getAuth } from '@githat/nextjs/server';\n *\n * export async function GET(request: Request) {\n * const auth = await getAuth(request, {\n * secretKey: process.env.GITHAT_SECRET_KEY\n * });\n *\n * if (!auth) {\n * return Response.json({ error: 'Unauthorized' }, { status: 401 });\n * }\n *\n * return Response.json({ userId: auth.userId });\n * }\n * ```\n */\nexport async function getAuth(\n request: Request,\n options: VerifyOptions = {}\n): Promise<AuthPayload | null> {\n // Try to get token from cookie first (httpOnly cookie mode)\n const cookieHeader = request.headers.get('cookie');\n let token: string | null = null;\n\n if (cookieHeader) {\n const cookies = parseCookies(cookieHeader);\n token = cookies[COOKIE_NAMES.accessToken] || null;\n }\n\n // Fallback to Authorization header\n if (!token) {\n const authHeader = request.headers.get('authorization');\n if (authHeader?.startsWith('Bearer ')) {\n token = authHeader.slice(7);\n }\n }\n\n // No token found — return null (unauthenticated)\n if (!token) {\n return null;\n }\n\n // Verify the token\n return verifyToken(token, options);\n}\n\n/**\n * Parse cookies from a cookie header string\n */\nfunction parseCookies(cookieHeader: string): Record<string, string> {\n const cookies: Record<string, string> = {};\n const pairs = cookieHeader.split(';');\n\n for (const pair of pairs) {\n const [name, ...rest] = pair.trim().split('=');\n if (name) {\n cookies[name] = rest.join('=');\n }\n }\n\n return cookies;\n}\n\n// ============================================================================\n// Org Metadata (Server-side)\n// ============================================================================\n\n/**\n * Get organization metadata from the server.\n *\n * @example\n * ```ts\n * import { getOrgMetadata } from '@githat/nextjs/server';\n *\n * const meta = await getOrgMetadata(orgId, {\n * token: accessToken,\n * apiUrl: 'https://api.githat.io'\n * });\n * console.log(meta.stripeAccountId);\n * ```\n */\nexport async function getOrgMetadata(\n orgId: string,\n options: { token: string; apiUrl?: string }\n): Promise<OrgMetadata> {\n const { token, apiUrl = DEFAULT_API_URL } = options;\n\n const response = await fetch(`${apiUrl}/orgs/${orgId}/metadata`, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n const data = await response.json().catch(() => ({}));\n throw new Error(data.error || 'Failed to get org metadata');\n }\n\n const data = await response.json();\n return data.metadata || {};\n}\n\n/**\n * Update organization metadata from the server.\n *\n * @example\n * ```ts\n * import { updateOrgMetadata } from '@githat/nextjs/server';\n *\n * await updateOrgMetadata(orgId, { stripeAccountId: 'acct_xxx' }, {\n * token: accessToken,\n * apiUrl: 'https://api.githat.io'\n * });\n * ```\n */\nexport async function updateOrgMetadata(\n orgId: string,\n metadata: OrgMetadata,\n options: { token: string; apiUrl?: string }\n): Promise<OrgMetadata> {\n const { token, apiUrl = DEFAULT_API_URL } = options;\n\n const response = await fetch(`${apiUrl}/orgs/${orgId}/metadata`, {\n method: 'PATCH',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(metadata),\n });\n\n if (!response.ok) {\n const data = await response.json().catch(() => ({}));\n throw new Error(data.error || 'Failed to update org metadata');\n }\n\n const data = await response.json();\n return data.metadata || {};\n}\n","import type { GitHatConfig } from './types';\n\nexport const DEFAULT_API_URL = 'https://api.githat.io';\n\nexport const TOKEN_KEYS = {\n accessToken: 'githat_access_token',\n refreshToken: 'githat_refresh_token',\n user: 'githat_user',\n org: 'githat_org',\n} as const;\n\nexport const COOKIE_NAMES = {\n accessToken: 'githat_access',\n refreshToken: 'githat_refresh',\n} as const;\n\nexport function resolveConfig(config: GitHatConfig): Required<GitHatConfig> {\n return {\n publishableKey: config.publishableKey,\n apiUrl: config.apiUrl || DEFAULT_API_URL,\n signInUrl: config.signInUrl || '/sign-in',\n signUpUrl: config.signUpUrl || '/sign-up',\n afterSignInUrl: config.afterSignInUrl || '/dashboard',\n afterSignOutUrl: config.afterSignOutUrl || '/',\n tokenStorage: config.tokenStorage || 'localStorage',\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,WAAsB;;;ACLf,IAAM,kBAAkB;;;AD2CxB,IAAM,eAAe;AAAA,EAC1B,aAAa;AAAA,EACb,cAAc;AAChB;AAyBA,eAAsB,YACpB,OACA,UAAyB,CAAC,GACJ;AACtB,QAAM,EAAE,WAAW,SAAS,gBAAgB,IAAI;AAEhD,MAAI,WAAW;AAEb,WAAO,mBAAmB,OAAO,SAAS;AAAA,EAC5C;AAGA,SAAO,kBAAkB,OAAO,MAAM;AACxC;AAKA,e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,SAAS,IAAI;AAChB,UAAMA,QAAO,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACnD,UAAM,IAAI,MAAMA,MAAK,SAAS,4BAA4B;AAAA,EAC5D;AAEA,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,SAAO,KAAK,YAAY,CAAC;AAC3B;AAeA,eAAsB,kBACpB,OACA,UACA,SACsB;AACtB,QAAM,EAAE,OAAO,SAAS,gBAAgB,IAAI;AAE5C,QAAM,WAAW,MAAM,MAAM,GAAG,MAAM,SAAS,KAAK,aAAa;AAAA,IAC/D,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,eAAe,UAAU,KAAK;AAAA,MAC9B,gBAAgB;AAAA,IAClB;AAAA,IACA,MAAM,KAAK,UAAU,QAAQ;AAAA,EAC/B,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,UAAMA,QAAO,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACnD,UAAM,IAAI,MAAMA,MAAK,SAAS,+BAA+B;AAAA,EAC/D;AAEA,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,SAAO,KAAK,YAAY,CAAC;AAC3B;","names":["data"]}
@@ -0,0 +1,147 @@
1
+ // src/server.ts
2
+ import * as jose from "jose";
3
+
4
+ // src/config.ts
5
+ var DEFAULT_API_URL = "https://api.githat.io";
6
+
7
+ // src/server.ts
8
+ var COOKIE_NAMES = {
9
+ accessToken: "githat_access",
10
+ refreshToken: "githat_refresh"
11
+ };
12
+ async function verifyToken(token, options = {}) {
13
+ const { secretKey, apiUrl = DEFAULT_API_URL } = options;
14
+ if (secretKey) {
15
+ return verifyTokenLocally(token, secretKey);
16
+ }
17
+ return verifyTokenViaAPI(token, apiUrl);
18
+ }
19
+ async function verifyTokenLocally(token, secretKey) {
20
+ try {
21
+ const secret = new TextEncoder().encode(secretKey);
22
+ const { payload } = await jose.jwtVerify(token, secret, {
23
+ algorithms: ["HS256"]
24
+ });
25
+ if (payload.type && payload.type !== "user") {
26
+ throw new Error("Invalid token type");
27
+ }
28
+ if (payload.tokenType !== "access") {
29
+ throw new Error("Invalid token type");
30
+ }
31
+ return {
32
+ userId: payload.userId,
33
+ email: payload.email,
34
+ orgId: payload.orgId || null,
35
+ orgSlug: payload.orgSlug || null,
36
+ role: payload.orgRole || null,
37
+ tier: null
38
+ // Tier requires DB lookup, not available in local verification
39
+ };
40
+ } catch (err) {
41
+ if (err instanceof jose.errors.JWTExpired) {
42
+ throw new Error("Token expired");
43
+ }
44
+ if (err instanceof jose.errors.JWTClaimValidationFailed) {
45
+ throw new Error("Invalid token claims");
46
+ }
47
+ if (err instanceof jose.errors.JWTInvalid) {
48
+ throw new Error("Invalid token");
49
+ }
50
+ if (err instanceof jose.errors.JWSSignatureVerificationFailed) {
51
+ throw new Error("Invalid token signature");
52
+ }
53
+ throw err;
54
+ }
55
+ }
56
+ async function verifyTokenViaAPI(token, apiUrl) {
57
+ const response = await fetch(`${apiUrl}/auth/verify`, {
58
+ method: "GET",
59
+ headers: {
60
+ Authorization: `Bearer ${token}`,
61
+ "Content-Type": "application/json"
62
+ }
63
+ });
64
+ if (!response.ok) {
65
+ const data2 = await response.json().catch(() => ({}));
66
+ throw new Error(data2.error || "Token verification failed");
67
+ }
68
+ const data = await response.json();
69
+ return {
70
+ userId: data.userId,
71
+ email: data.email,
72
+ orgId: data.orgId,
73
+ orgSlug: data.orgSlug,
74
+ role: data.role,
75
+ tier: data.tier
76
+ };
77
+ }
78
+ async function getAuth(request, options = {}) {
79
+ const cookieHeader = request.headers.get("cookie");
80
+ let token = null;
81
+ if (cookieHeader) {
82
+ const cookies = parseCookies(cookieHeader);
83
+ token = cookies[COOKIE_NAMES.accessToken] || null;
84
+ }
85
+ if (!token) {
86
+ const authHeader = request.headers.get("authorization");
87
+ if (authHeader?.startsWith("Bearer ")) {
88
+ token = authHeader.slice(7);
89
+ }
90
+ }
91
+ if (!token) {
92
+ return null;
93
+ }
94
+ return verifyToken(token, options);
95
+ }
96
+ function parseCookies(cookieHeader) {
97
+ const cookies = {};
98
+ const pairs = cookieHeader.split(";");
99
+ for (const pair of pairs) {
100
+ const [name, ...rest] = pair.trim().split("=");
101
+ if (name) {
102
+ cookies[name] = rest.join("=");
103
+ }
104
+ }
105
+ return cookies;
106
+ }
107
+ async function getOrgMetadata(orgId, options) {
108
+ const { token, apiUrl = DEFAULT_API_URL } = options;
109
+ const response = await fetch(`${apiUrl}/orgs/${orgId}/metadata`, {
110
+ method: "GET",
111
+ headers: {
112
+ Authorization: `Bearer ${token}`,
113
+ "Content-Type": "application/json"
114
+ }
115
+ });
116
+ if (!response.ok) {
117
+ const data2 = await response.json().catch(() => ({}));
118
+ throw new Error(data2.error || "Failed to get org metadata");
119
+ }
120
+ const data = await response.json();
121
+ return data.metadata || {};
122
+ }
123
+ async function updateOrgMetadata(orgId, metadata, options) {
124
+ const { token, apiUrl = DEFAULT_API_URL } = options;
125
+ const response = await fetch(`${apiUrl}/orgs/${orgId}/metadata`, {
126
+ method: "PATCH",
127
+ headers: {
128
+ Authorization: `Bearer ${token}`,
129
+ "Content-Type": "application/json"
130
+ },
131
+ body: JSON.stringify(metadata)
132
+ });
133
+ if (!response.ok) {
134
+ const data2 = await response.json().catch(() => ({}));
135
+ throw new Error(data2.error || "Failed to update org metadata");
136
+ }
137
+ const data = await response.json();
138
+ return data.metadata || {};
139
+ }
140
+ export {
141
+ COOKIE_NAMES,
142
+ getAuth,
143
+ getOrgMetadata,
144
+ updateOrgMetadata,
145
+ verifyToken
146
+ };
147
+ //# sourceMappingURL=server.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server.ts","../src/config.ts"],"sourcesContent":["/**\n * @githat/nextjs/server\n *\n * Server-side utilities for token verification in Next.js API routes and middleware.\n * This module runs on the server only — do not import in client components.\n */\n\nimport * as jose from 'jose';\nimport { DEFAULT_API_URL } from './config';\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface AuthPayload {\n userId: string;\n email: string;\n orgId: string | null;\n orgSlug: string | null;\n role: 'owner' | 'admin' | 'member' | null;\n tier: 'free' | 'basic' | 'pro' | 'enterprise' | null;\n}\n\nexport interface VerifyOptions {\n /**\n * Secret key for local JWT verification. If provided, tokens are verified\n * locally without making an API call (~1ms vs ~50-100ms).\n * Must match the JWT_SECRET used by the GitHat backend.\n */\n secretKey?: string;\n\n /**\n * API URL for remote token verification. Defaults to https://api.githat.io\n */\n apiUrl?: string;\n}\n\nexport interface OrgMetadata {\n [key: string]: unknown;\n}\n\n// ============================================================================\n// Cookie Names\n// ============================================================================\n\nexport const COOKIE_NAMES = {\n accessToken: 'githat_access',\n refreshToken: 'githat_refresh',\n} as const;\n\n// ============================================================================\n// Token Verification\n// ============================================================================\n\n/**\n * Verify a JWT token and return the decoded auth payload.\n *\n * Supports two verification modes:\n * 1. Local verification (recommended for performance): Pass `secretKey` option\n * 2. API-based verification: No secret key needed, calls api.githat.io/auth/verify\n *\n * @example Local verification (fast, ~1ms)\n * ```ts\n * const auth = await verifyToken(token, {\n * secretKey: process.env.GITHAT_SECRET_KEY\n * });\n * ```\n *\n * @example API-based verification (simpler setup)\n * ```ts\n * const auth = await verifyToken(token);\n * ```\n */\nexport async function verifyToken(\n token: string,\n options: VerifyOptions = {}\n): Promise<AuthPayload> {\n const { secretKey, apiUrl = DEFAULT_API_URL } = options;\n\n if (secretKey) {\n // Local verification using jose\n return verifyTokenLocally(token, secretKey);\n }\n\n // API-based verification\n return verifyTokenViaAPI(token, apiUrl);\n}\n\n/**\n * Verify token locally using the secret key (no network call)\n */\nasync function verifyTokenLocally(\n token: string,\n secretKey: string\n): Promise<AuthPayload> {\n try {\n const secret = new TextEncoder().encode(secretKey);\n const { payload } = await jose.jwtVerify(token, secret, {\n algorithms: ['HS256'],\n });\n\n // Validate this is a user access token\n if (payload.type && payload.type !== 'user') {\n throw new Error('Invalid token type');\n }\n if (payload.tokenType !== 'access') {\n throw new Error('Invalid token type');\n }\n\n return {\n userId: payload.userId as string,\n email: payload.email as string,\n orgId: (payload.orgId as string) || null,\n orgSlug: (payload.orgSlug as string) || null,\n role: (payload.orgRole as AuthPayload['role']) || null,\n tier: null, // Tier requires DB lookup, not available in local verification\n };\n } catch (err) {\n if (err instanceof jose.errors.JWTExpired) {\n throw new Error('Token expired');\n }\n if (err instanceof jose.errors.JWTClaimValidationFailed) {\n throw new Error('Invalid token claims');\n }\n if (err instanceof jose.errors.JWTInvalid) {\n throw new Error('Invalid token');\n }\n // JWSSignatureVerificationFailed is used for invalid signatures\n if (err instanceof jose.errors.JWSSignatureVerificationFailed) {\n throw new Error('Invalid token signature');\n }\n throw err;\n }\n}\n\n/**\n * Verify token via API call to api.githat.io/auth/verify\n */\nasync function verifyTokenViaAPI(\n token: string,\n apiUrl: string\n): Promise<AuthPayload> {\n const response = await fetch(`${apiUrl}/auth/verify`, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n const data = await response.json().catch(() => ({}));\n throw new Error(data.error || 'Token verification failed');\n }\n\n const data = await response.json();\n return {\n userId: data.userId,\n email: data.email,\n orgId: data.orgId,\n orgSlug: data.orgSlug,\n role: data.role,\n tier: data.tier,\n };\n}\n\n// ============================================================================\n// Request Helpers\n// ============================================================================\n\n/**\n * Extract and verify the auth token from a Next.js request.\n * Checks cookies first (for httpOnly cookie mode), then Authorization header.\n *\n * Returns null if no token is found (unauthenticated request).\n * Throws if a token is found but is invalid/expired.\n *\n * @example In a Next.js API route\n * ```ts\n * import { getAuth } from '@githat/nextjs/server';\n *\n * export async function GET(request: Request) {\n * const auth = await getAuth(request, {\n * secretKey: process.env.GITHAT_SECRET_KEY\n * });\n *\n * if (!auth) {\n * return Response.json({ error: 'Unauthorized' }, { status: 401 });\n * }\n *\n * return Response.json({ userId: auth.userId });\n * }\n * ```\n */\nexport async function getAuth(\n request: Request,\n options: VerifyOptions = {}\n): Promise<AuthPayload | null> {\n // Try to get token from cookie first (httpOnly cookie mode)\n const cookieHeader = request.headers.get('cookie');\n let token: string | null = null;\n\n if (cookieHeader) {\n const cookies = parseCookies(cookieHeader);\n token = cookies[COOKIE_NAMES.accessToken] || null;\n }\n\n // Fallback to Authorization header\n if (!token) {\n const authHeader = request.headers.get('authorization');\n if (authHeader?.startsWith('Bearer ')) {\n token = authHeader.slice(7);\n }\n }\n\n // No token found — return null (unauthenticated)\n if (!token) {\n return null;\n }\n\n // Verify the token\n return verifyToken(token, options);\n}\n\n/**\n * Parse cookies from a cookie header string\n */\nfunction parseCookies(cookieHeader: string): Record<string, string> {\n const cookies: Record<string, string> = {};\n const pairs = cookieHeader.split(';');\n\n for (const pair of pairs) {\n const [name, ...rest] = pair.trim().split('=');\n if (name) {\n cookies[name] = rest.join('=');\n }\n }\n\n return cookies;\n}\n\n// ============================================================================\n// Org Metadata (Server-side)\n// ============================================================================\n\n/**\n * Get organization metadata from the server.\n *\n * @example\n * ```ts\n * import { getOrgMetadata } from '@githat/nextjs/server';\n *\n * const meta = await getOrgMetadata(orgId, {\n * token: accessToken,\n * apiUrl: 'https://api.githat.io'\n * });\n * console.log(meta.stripeAccountId);\n * ```\n */\nexport async function getOrgMetadata(\n orgId: string,\n options: { token: string; apiUrl?: string }\n): Promise<OrgMetadata> {\n const { token, apiUrl = DEFAULT_API_URL } = options;\n\n const response = await fetch(`${apiUrl}/orgs/${orgId}/metadata`, {\n method: 'GET',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n const data = await response.json().catch(() => ({}));\n throw new Error(data.error || 'Failed to get org metadata');\n }\n\n const data = await response.json();\n return data.metadata || {};\n}\n\n/**\n * Update organization metadata from the server.\n *\n * @example\n * ```ts\n * import { updateOrgMetadata } from '@githat/nextjs/server';\n *\n * await updateOrgMetadata(orgId, { stripeAccountId: 'acct_xxx' }, {\n * token: accessToken,\n * apiUrl: 'https://api.githat.io'\n * });\n * ```\n */\nexport async function updateOrgMetadata(\n orgId: string,\n metadata: OrgMetadata,\n options: { token: string; apiUrl?: string }\n): Promise<OrgMetadata> {\n const { token, apiUrl = DEFAULT_API_URL } = options;\n\n const response = await fetch(`${apiUrl}/orgs/${orgId}/metadata`, {\n method: 'PATCH',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(metadata),\n });\n\n if (!response.ok) {\n const data = await response.json().catch(() => ({}));\n throw new Error(data.error || 'Failed to update org metadata');\n }\n\n const data = await response.json();\n return data.metadata || {};\n}\n","import type { GitHatConfig } from './types';\n\nexport const DEFAULT_API_URL = 'https://api.githat.io';\n\nexport const TOKEN_KEYS = {\n accessToken: 'githat_access_token',\n refreshToken: 'githat_refresh_token',\n user: 'githat_user',\n org: 'githat_org',\n} as const;\n\nexport const COOKIE_NAMES = {\n accessToken: 'githat_access',\n refreshToken: 'githat_refresh',\n} as const;\n\nexport function resolveConfig(config: GitHatConfig): Required<GitHatConfig> {\n return {\n publishableKey: config.publishableKey,\n apiUrl: config.apiUrl || DEFAULT_API_URL,\n signInUrl: config.signInUrl || '/sign-in',\n signUpUrl: config.signUpUrl || '/sign-up',\n afterSignInUrl: config.afterSignInUrl || '/dashboard',\n afterSignOutUrl: config.afterSignOutUrl || '/',\n tokenStorage: config.tokenStorage || 'localStorage',\n };\n}\n"],"mappings":";AAOA,YAAY,UAAU;;;ACLf,IAAM,kBAAkB;;;AD2CxB,IAAM,eAAe;AAAA,EAC1B,aAAa;AAAA,EACb,cAAc;AAChB;AAyBA,eAAsB,YACpB,OACA,UAAyB,CAAC,GACJ;AACtB,QAAM,EAAE,WAAW,SAAS,gBAAgB,IAAI;AAEhD,MAAI,WAAW;AAEb,WAAO,mBAAmB,OAAO,SAAS;AAAA,EAC5C;AAGA,SAAO,kBAAkB,OAAO,MAAM;AACxC;AAKA,eAAe,mBACb,OACA,WACsB;AACtB,MAAI;AACF,UAAM,SAAS,IAAI,YAAY,EAAE,OAAO,SAAS;AACjD,UAAM,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IAAI,MAAMA,MAAK,SAAS,4BAA4B;AAAA,EAC5D;AAEA,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,SAAO,KAAK,YAAY,CAAC;AAC3B;AAeA,eAAsB,kBACpB,OACA,UACA,SACsB;AACtB,QAAM,EAAE,OAAO,SAAS,gBAAgB,IAAI;AAE5C,QAAM,WAAW,MAAM,MAAM,GAAG,MAAM,SAAS,KAAK,aAAa;AAAA,IAC/D,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,eAAe,UAAU,KAAK;AAAA,MAC9B,gBAAgB;AAAA,IAClB;AAAA,IACA,MAAM,KAAK,UAAU,QAAQ;AAAA,EAC/B,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,UAAMA,QAAO,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACnD,UAAM,IAAI,MAAMA,MAAK,SAAS,+BAA+B;AAAA,EAC/D;AAEA,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,SAAO,KAAK,YAAY,CAAC;AAC3B;","names":["data"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@githat/nextjs",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "GitHat identity SDK for Next.js applications",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -16,6 +16,16 @@
16
16
  "import": "./dist/middleware.mjs",
17
17
  "require": "./dist/middleware.js"
18
18
  },
19
+ "./proxy": {
20
+ "types": "./dist/proxy.d.ts",
21
+ "import": "./dist/proxy.mjs",
22
+ "require": "./dist/proxy.js"
23
+ },
24
+ "./server": {
25
+ "types": "./dist/server.d.ts",
26
+ "import": "./dist/server.mjs",
27
+ "require": "./dist/server.js"
28
+ },
19
29
  "./styles": "./dist/githat.css"
20
30
  },
21
31
  "files": ["dist"],
@@ -23,6 +33,9 @@
23
33
  "build": "tsup && cp src/styles/githat.css dist/githat.css",
24
34
  "dev": "tsup --watch"
25
35
  },
36
+ "dependencies": {
37
+ "jose": "^5.2.0"
38
+ },
26
39
  "peerDependencies": {
27
40
  "next": ">=14.0.0",
28
41
  "react": ">=18.0.0",