@imtbl/auth-next-client 2.12.5-alpha.13

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,39 @@
1
+ import { decodeJwtPayload } from '@imtbl/auth';
2
+ import { DEFAULT_TOKEN_EXPIRY_MS } from '../constants';
3
+
4
+ /**
5
+ * JWT payload with expiry claim
6
+ */
7
+ interface JwtPayload {
8
+ exp?: number;
9
+ iat?: number;
10
+ [key: string]: unknown;
11
+ }
12
+
13
+ /**
14
+ * Extract the expiry timestamp from a JWT access token.
15
+ * Returns the expiry as a Unix timestamp in milliseconds.
16
+ *
17
+ * @param accessToken - JWT access token
18
+ * @returns Expiry timestamp in milliseconds, or a default 15-minute expiry if extraction fails
19
+ */
20
+ export function getTokenExpiry(accessToken: string | undefined): number {
21
+ if (!accessToken) {
22
+ return Date.now() + DEFAULT_TOKEN_EXPIRY_MS;
23
+ }
24
+
25
+ try {
26
+ const payload = decodeJwtPayload<JwtPayload>(accessToken);
27
+
28
+ if (payload.exp && typeof payload.exp === 'number') {
29
+ // JWT exp is in seconds, convert to milliseconds
30
+ return payload.exp * 1000;
31
+ }
32
+
33
+ // No exp claim, fall back to default
34
+ return Date.now() + DEFAULT_TOKEN_EXPIRY_MS;
35
+ } catch {
36
+ // Failed to decode token, fall back to default
37
+ return Date.now() + DEFAULT_TOKEN_EXPIRY_MS;
38
+ }
39
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": [],
4
+ "include": ["src"]
5
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDirs": ["src"],
6
+ "customConditions": ["development"],
7
+ "types": ["node"],
8
+ "jsx": "react-jsx"
9
+ },
10
+ "include": ["src"],
11
+ "exclude": [
12
+ "node_modules",
13
+ "dist",
14
+ "src/**/*.test.ts",
15
+ "src/**/*.test.tsx",
16
+ "src/**/*.spec.ts",
17
+ "src/**/*.spec.tsx"
18
+ ]
19
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
6
+ "declarationDir": "./dist/node"
7
+ }
8
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { defineConfig, type Options } from "tsup";
2
+
3
+ // Peer dependencies that should never be bundled
4
+ const peerExternal = [
5
+ "react",
6
+ "next",
7
+ "next-auth",
8
+ "next/navigation",
9
+ "next/headers",
10
+ "next/server",
11
+ ];
12
+
13
+ const baseConfig: Options = {
14
+ outDir: "dist/node",
15
+ format: ["esm", "cjs"],
16
+ target: "es2022",
17
+ platform: "node",
18
+ dts: false,
19
+ };
20
+
21
+ export default defineConfig([
22
+ {
23
+ ...baseConfig,
24
+ entry: {
25
+ index: "src/index.ts",
26
+ },
27
+ external: peerExternal,
28
+ clean: true,
29
+ banner: {
30
+ js: "'use client';",
31
+ },
32
+ },
33
+ ]);