delta-auth-next 0.1.19 → 0.1.22
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/DeltaProvider.d.ts.map +1 -1
- package/dist/DeltaProvider.js +17 -16
- package/dist/DeltaProvider.js.map +1 -1
- package/dist/alert.d.ts +5 -0
- package/dist/alert.d.ts.map +1 -0
- package/dist/alert.js +21 -0
- package/dist/alert.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +16 -15
- package/src/DeltaProvider.tsx +24 -20
- package/src/alert.tsx +30 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +0 -17
- package/delta-auth-next-0.1.14.tgz +0 -0
- package/pnpm-workspace.yaml +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeltaProvider.d.ts","sourceRoot":"","sources":["../src/DeltaProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAGhE,OAAO,EAAE,eAAe,EAAiB,MAAM,SAAS,CAAC;AAGzD,UAAU,KAAK;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,iBAAiB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"DeltaProvider.d.ts","sourceRoot":"","sources":["../src/DeltaProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAGhE,OAAO,EAAE,eAAe,EAAiB,MAAM,SAAS,CAAC;AAGzD,UAAU,KAAK;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,iBAAiB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,KAAK,2CA8G5D"}
|
package/dist/DeltaProvider.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useEffect, useCallback } from 'react';
|
|
4
4
|
import { AuthContext } from './context';
|
|
5
5
|
import { createAuthClient } from './client/authClient';
|
|
6
|
-
import {
|
|
6
|
+
import { useSimpleToast } from './alert';
|
|
7
7
|
export function DeltaAuthProvider({ config, children }) {
|
|
8
8
|
const [session, setSession] = useState(null);
|
|
9
9
|
const [loading, setLoading] = useState(true);
|
|
10
10
|
const [enabled, setEnabled] = useState(true); // disables provider if misconfigured
|
|
11
|
+
const { show, Toast } = useSimpleToast();
|
|
11
12
|
// 🔹 Disable if no publishable key
|
|
12
13
|
useEffect(() => {
|
|
13
14
|
if (!config?.publishableKey) {
|
|
14
|
-
|
|
15
|
+
show('DeltaAuth: publishableKey is required');
|
|
15
16
|
setEnabled(false);
|
|
16
17
|
}
|
|
17
18
|
}, [config?.publishableKey]);
|
|
@@ -33,13 +34,13 @@ export function DeltaAuthProvider({ config, children }) {
|
|
|
33
34
|
catch (err) {
|
|
34
35
|
setSession(null);
|
|
35
36
|
if (config.showAlerts ?? true) {
|
|
36
|
-
|
|
37
|
+
show(err.response?.data?.error ?? 'Auth failed');
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
finally {
|
|
40
41
|
setLoading(false);
|
|
41
42
|
}
|
|
42
|
-
}, [client, enabled, config.showAlerts]);
|
|
43
|
+
}, [client, enabled, config.showAlerts, show]);
|
|
43
44
|
// 🔹 Fetch detailed user info
|
|
44
45
|
const fetchUserDetails = useCallback(async () => {
|
|
45
46
|
if (!session?.user || !client)
|
|
@@ -62,15 +63,15 @@ export function DeltaAuthProvider({ config, children }) {
|
|
|
62
63
|
const isLocalhost = hostname.includes('localhost') || hostname.includes('127.0.0.1');
|
|
63
64
|
const isProd = protocol === 'https:';
|
|
64
65
|
if (isLocalhost && config.publishableKey?.startsWith('pk_live')) {
|
|
65
|
-
|
|
66
|
+
show('You are using a live key on localhost. Use a test key for development.');
|
|
66
67
|
setEnabled(false);
|
|
67
68
|
}
|
|
68
69
|
if (isProd && config.publishableKey?.startsWith('pk_test')) {
|
|
69
|
-
|
|
70
|
+
show('You are using a test key in production. Use a live key.');
|
|
70
71
|
}
|
|
71
72
|
if (enabled)
|
|
72
73
|
fetchSession();
|
|
73
|
-
}, [config.publishableKey, fetchSession, enabled]);
|
|
74
|
+
}, [config.publishableKey, fetchSession, enabled, show]);
|
|
74
75
|
// 🔹 Auto refresh session
|
|
75
76
|
useEffect(() => {
|
|
76
77
|
if (!enabled || !config.autoRefresh)
|
|
@@ -80,13 +81,13 @@ export function DeltaAuthProvider({ config, children }) {
|
|
|
80
81
|
}, [fetchSession, config.autoRefresh, config.refreshInterval, enabled]);
|
|
81
82
|
if (!enabled)
|
|
82
83
|
return _jsx(_Fragment, { children: children }); // render children without auth if disabled
|
|
83
|
-
return (_jsx(AuthContext.Provider, { value: {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
return (_jsxs(_Fragment, { children: [_jsx(AuthContext.Provider, { value: {
|
|
85
|
+
session,
|
|
86
|
+
user: session?.user ?? null,
|
|
87
|
+
loading,
|
|
88
|
+
isAuthenticated: !!session,
|
|
89
|
+
client,
|
|
90
|
+
fetchUser: fetchUserDetails,
|
|
91
|
+
}, children: children }), _jsx(Toast, {}), " "] }));
|
|
91
92
|
}
|
|
92
93
|
//# sourceMappingURL=DeltaProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeltaProvider.js","sourceRoot":"","sources":["../src/DeltaProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAc,EAAE,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E,IAAI,CAAC,CAAC,CAAC;IAEzD,0BAA0B;IAC1B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW;YAAE,OAAO;QAE5C,MAAM,QAAQ,GAAG,WAAW,CAC1B,YAAY,EACZ,MAAM,CAAC,eAAe,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CACxC,CAAC;QACF,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;IAExE,IAAI,CAAC,OAAO;QAAE,OAAO,4BAAG,QAAQ,GAAI,CAAC,CAAC,2CAA2C;IAEjF,OAAO,CACL,8BACE,KAAC,WAAW,CAAC,QAAQ,IACnB,KAAK,EAAE;oBACL,OAAO;oBACP,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,IAAI;oBAC3B,OAAO;oBACP,eAAe,EAAE,CAAC,CAAC,OAAO;oBAC1B,MAAM;oBACN,SAAS,EAAE,gBAAgB;iBAC5B,YAEA,QAAQ,GACY,EACvB,KAAC,KAAK,KAAG,SACR,CACJ,CAAC;AACJ,CAAC"}
|
package/dist/alert.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alert.d.ts","sourceRoot":"","sources":["../src/alert.tsx"],"names":[],"mappings":"AAEA,wBAAgB,cAAc;gBAGT,MAAM;;EAwB1B"}
|
package/dist/alert.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
export function useSimpleToast() {
|
|
4
|
+
const [message, setMessage] = useState(null);
|
|
5
|
+
const show = (msg, duration = 3000) => {
|
|
6
|
+
setMessage(msg);
|
|
7
|
+
setTimeout(() => setMessage(null), duration);
|
|
8
|
+
};
|
|
9
|
+
const Toast = () => message ? (_jsx("div", { style: {
|
|
10
|
+
position: 'fixed',
|
|
11
|
+
top: 20,
|
|
12
|
+
right: 20,
|
|
13
|
+
background: 'rgba(0,0,0,0.85)',
|
|
14
|
+
color: '#fff',
|
|
15
|
+
padding: '10px 20px',
|
|
16
|
+
borderRadius: 6,
|
|
17
|
+
zIndex: 9999,
|
|
18
|
+
}, children: message })) : null;
|
|
19
|
+
return { show, Toast };
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=alert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alert.js","sourceRoot":"","sources":["../src/alert.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAa,MAAM,OAAO,CAAC;AAE5C,MAAM,UAAU,cAAc;IAC5B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAE5D,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,QAAQ,GAAG,IAAI,EAAE,EAAE;QAC5C,UAAU,CAAC,GAAG,CAAC,CAAC;QAChB,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG,GAAG,EAAE,CACjB,OAAO,CAAC,CAAC,CAAC,CACR,cACE,KAAK,EAAE;YACL,QAAQ,EAAE,OAAO;YACjB,GAAG,EAAE,EAAE;YACP,KAAK,EAAE,EAAE;YACT,UAAU,EAAE,kBAAkB;YAC9B,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,WAAW;YACpB,YAAY,EAAE,CAAC;YACf,MAAM,EAAE,IAAI;SACb,YAEA,OAAO,GACJ,CACP,CAAC,CAAC,CAAC,IAAI,CAAC;IAEX,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACzB,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "delta-auth-next",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"watch": "tsc --watch"
|
|
11
|
+
},
|
|
6
12
|
"author": "Samuel Onwodi",
|
|
7
13
|
"keywords": [
|
|
8
14
|
"react",
|
|
9
15
|
"auth",
|
|
10
16
|
"library"
|
|
11
17
|
],
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"build": "tsc"
|
|
18
|
+
"packageManager": "pnpm@10.28.2",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"axios": "^1.13.4"
|
|
16
21
|
},
|
|
17
|
-
"packageManager": "pnpm@10.13.1",
|
|
18
22
|
"devDependencies": {
|
|
19
23
|
"@types/node": "^25.2.0",
|
|
20
|
-
"@types/react": "^
|
|
21
|
-
"@types/react-dom": "^
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"sonner": "^2.0.7",
|
|
27
|
-
"typescript": "^5.9.3",
|
|
28
|
-
"uuid": "^13.0.0"
|
|
24
|
+
"@types/react": "^18.3.27",
|
|
25
|
+
"@types/react-dom": "^18.3.7",
|
|
26
|
+
"react": "^18.3.1",
|
|
27
|
+
"react-dom": "^18.3.1",
|
|
28
|
+
"tsup": "^8.5.1",
|
|
29
|
+
"typescript": "^5.9.3"
|
|
29
30
|
}
|
|
30
31
|
}
|
package/src/DeltaProvider.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import React, { useState, useEffect, useCallback } from 'react';
|
|
|
3
3
|
import { AuthContext } from './context';
|
|
4
4
|
import { createAuthClient } from './client/authClient';
|
|
5
5
|
import { DeltaAuthConfig, Session, User } from './types';
|
|
6
|
-
import {
|
|
6
|
+
import { useSimpleToast } from './alert';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
9
|
config: DeltaAuthConfig;
|
|
@@ -14,11 +14,12 @@ export function DeltaAuthProvider({ config, children }: Props) {
|
|
|
14
14
|
const [session, setSession] = useState<Session | null>(null);
|
|
15
15
|
const [loading, setLoading] = useState(true);
|
|
16
16
|
const [enabled, setEnabled] = useState(true); // disables provider if misconfigured
|
|
17
|
-
|
|
17
|
+
const { show, Toast } = useSimpleToast();
|
|
18
|
+
|
|
18
19
|
// 🔹 Disable if no publishable key
|
|
19
20
|
useEffect(() => {
|
|
20
21
|
if (!config?.publishableKey) {
|
|
21
|
-
|
|
22
|
+
show('DeltaAuth: publishableKey is required');
|
|
22
23
|
setEnabled(false);
|
|
23
24
|
}
|
|
24
25
|
}, [config?.publishableKey]);
|
|
@@ -42,12 +43,12 @@ export function DeltaAuthProvider({ config, children }: Props) {
|
|
|
42
43
|
} catch (err: any) {
|
|
43
44
|
setSession(null);
|
|
44
45
|
if (config.showAlerts ?? true) {
|
|
45
|
-
|
|
46
|
+
show(err.response?.data?.error ?? 'Auth failed');
|
|
46
47
|
}
|
|
47
48
|
} finally {
|
|
48
49
|
setLoading(false);
|
|
49
50
|
}
|
|
50
|
-
}, [client, enabled, config.showAlerts]);
|
|
51
|
+
}, [client, enabled, config.showAlerts, show]);
|
|
51
52
|
|
|
52
53
|
// 🔹 Fetch detailed user info
|
|
53
54
|
const fetchUserDetails = useCallback(async () => {
|
|
@@ -76,18 +77,18 @@ export function DeltaAuthProvider({ config, children }: Props) {
|
|
|
76
77
|
const isProd = protocol === 'https:';
|
|
77
78
|
|
|
78
79
|
if (isLocalhost && config.publishableKey?.startsWith('pk_live')) {
|
|
79
|
-
|
|
80
|
+
show(
|
|
80
81
|
'You are using a live key on localhost. Use a test key for development.'
|
|
81
82
|
);
|
|
82
83
|
setEnabled(false);
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
if (isProd && config.publishableKey?.startsWith('pk_test')) {
|
|
86
|
-
|
|
87
|
+
show('You are using a test key in production. Use a live key.');
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
if (enabled) fetchSession();
|
|
90
|
-
}, [config.publishableKey, fetchSession, enabled]);
|
|
91
|
+
}, [config.publishableKey, fetchSession, enabled, show]);
|
|
91
92
|
|
|
92
93
|
// 🔹 Auto refresh session
|
|
93
94
|
useEffect(() => {
|
|
@@ -103,17 +104,20 @@ export function DeltaAuthProvider({ config, children }: Props) {
|
|
|
103
104
|
if (!enabled) return <>{children}</>; // render children without auth if disabled
|
|
104
105
|
|
|
105
106
|
return (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
107
|
+
<>
|
|
108
|
+
<AuthContext.Provider
|
|
109
|
+
value={{
|
|
110
|
+
session,
|
|
111
|
+
user: session?.user ?? null,
|
|
112
|
+
loading,
|
|
113
|
+
isAuthenticated: !!session,
|
|
114
|
+
client,
|
|
115
|
+
fetchUser: fetchUserDetails,
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
{children}
|
|
119
|
+
</AuthContext.Provider>
|
|
120
|
+
<Toast /> {/* 🔹 render the toast container */}
|
|
121
|
+
</>
|
|
118
122
|
);
|
|
119
123
|
}
|
package/src/alert.tsx
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useSimpleToast() {
|
|
4
|
+
const [message, setMessage] = useState<string | null>(null);
|
|
5
|
+
|
|
6
|
+
const show = (msg: string, duration = 3000) => {
|
|
7
|
+
setMessage(msg);
|
|
8
|
+
setTimeout(() => setMessage(null), duration);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const Toast = () =>
|
|
12
|
+
message ? (
|
|
13
|
+
<div
|
|
14
|
+
style={{
|
|
15
|
+
position: 'fixed',
|
|
16
|
+
top: 20,
|
|
17
|
+
right: 20,
|
|
18
|
+
background: 'rgba(0,0,0,0.85)',
|
|
19
|
+
color: '#fff',
|
|
20
|
+
padding: '10px 20px',
|
|
21
|
+
borderRadius: 6,
|
|
22
|
+
zIndex: 9999,
|
|
23
|
+
}}
|
|
24
|
+
>
|
|
25
|
+
{message}
|
|
26
|
+
</div>
|
|
27
|
+
) : null;
|
|
28
|
+
|
|
29
|
+
return { show, Toast };
|
|
30
|
+
}
|
package/src/index.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
// Input / Output
|
|
4
3
|
"rootDir": "src",
|
|
5
4
|
"outDir": "dist",
|
|
6
5
|
"declaration": true,
|
|
7
6
|
"declarationMap": true,
|
|
8
7
|
"sourceMap": true,
|
|
9
|
-
|
|
10
|
-
// Module / Target
|
|
11
8
|
"module": "ESNext",
|
|
12
9
|
"target": "ES2022",
|
|
13
10
|
"moduleResolution": "node",
|
|
14
|
-
|
|
15
|
-
// JSX support
|
|
16
11
|
"jsx": "react-jsx",
|
|
17
|
-
|
|
18
|
-
// Type Checking
|
|
19
12
|
"strict": true,
|
|
20
13
|
"noImplicitAny": true,
|
|
21
|
-
"exactOptionalPropertyTypes": true,
|
|
22
|
-
"noUncheckedIndexedAccess": true,
|
|
23
|
-
"isolatedModules": true,
|
|
24
|
-
|
|
25
|
-
// Skip library type checks for faster compilation
|
|
26
14
|
"skipLibCheck": true,
|
|
27
|
-
|
|
28
|
-
// Types
|
|
29
|
-
"types": ["node", "react", "react-dom"],
|
|
30
|
-
|
|
31
|
-
// Helps with ES modules and npm publishing
|
|
32
15
|
"esModuleInterop": true,
|
|
33
16
|
"forceConsistentCasingInFileNames": true
|
|
34
17
|
},
|
|
Binary file
|
package/pnpm-workspace.yaml
DELETED
|
File without changes
|