@onjunctiondev/auth 0.1.3 → 0.2.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.
- package/dist/react/index.cjs +65 -3
- package/dist/react/index.d.cts +31 -1
- package/dist/react/index.d.ts +31 -1
- package/dist/react/index.js +62 -3
- package/package.json +9 -1
package/dist/react/index.cjs
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -15,7 +19,65 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
15
19
|
|
|
16
20
|
// src/react/index.ts
|
|
17
21
|
var react_exports = {};
|
|
22
|
+
__export(react_exports, {
|
|
23
|
+
JunctionProvider: () => JunctionProvider,
|
|
24
|
+
useJunctionAuth: () => useJunctionAuth,
|
|
25
|
+
useJunctionSession: () => useJunctionSession,
|
|
26
|
+
useJunctionUser: () => useJunctionUser
|
|
27
|
+
});
|
|
18
28
|
module.exports = __toCommonJS(react_exports);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
var JunctionAuthContext = (0, import_react.createContext)(null);
|
|
31
|
+
function JunctionProvider(props) {
|
|
32
|
+
const { client, children } = props;
|
|
33
|
+
const [state, setState] = (0, import_react.useState)(() => ({
|
|
34
|
+
session: client.auth.getSession().data?.session ?? null,
|
|
35
|
+
isLoading: true
|
|
36
|
+
}));
|
|
37
|
+
(0, import_react.useEffect)(() => {
|
|
38
|
+
const sub = client.auth.onAuthStateChange((_event, session) => {
|
|
39
|
+
setState({ session, isLoading: false });
|
|
40
|
+
});
|
|
41
|
+
return () => sub.unsubscribe();
|
|
42
|
+
}, [client]);
|
|
43
|
+
const value = (0, import_react.useMemo)(() => ({ client, state }), [client, state]);
|
|
44
|
+
return (0, import_react.createElement)(JunctionAuthContext.Provider, { value }, children);
|
|
45
|
+
}
|
|
46
|
+
function useCtx() {
|
|
47
|
+
const ctx = (0, import_react.useContext)(JunctionAuthContext);
|
|
48
|
+
if (!ctx) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
"Junction auth hook called outside <JunctionProvider>. Wrap your app in <JunctionProvider client={...}>."
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return ctx;
|
|
54
|
+
}
|
|
55
|
+
function useJunctionSession() {
|
|
56
|
+
const { state } = useCtx();
|
|
57
|
+
return { session: state.session, isLoading: state.isLoading };
|
|
58
|
+
}
|
|
59
|
+
function useJunctionUser() {
|
|
60
|
+
const { state } = useCtx();
|
|
61
|
+
return { user: state.session?.user ?? null, isLoading: state.isLoading };
|
|
62
|
+
}
|
|
63
|
+
function useJunctionAuth() {
|
|
64
|
+
const { client } = useCtx();
|
|
65
|
+
const signIn = (0, import_react.useCallback)(
|
|
66
|
+
(email, password) => client.auth.signIn({ email, password }),
|
|
67
|
+
[client]
|
|
68
|
+
);
|
|
69
|
+
const signUp = (0, import_react.useCallback)(
|
|
70
|
+
(email, password) => client.auth.signUp({ email, password }),
|
|
71
|
+
[client]
|
|
72
|
+
);
|
|
73
|
+
const signOut = (0, import_react.useCallback)(() => client.auth.signOut(), [client]);
|
|
74
|
+
const refreshSession = (0, import_react.useCallback)(() => client.auth.refreshSession(), [client]);
|
|
75
|
+
return { signIn, signUp, signOut, refreshSession };
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
JunctionProvider,
|
|
80
|
+
useJunctionAuth,
|
|
81
|
+
useJunctionSession,
|
|
82
|
+
useJunctionUser
|
|
83
|
+
});
|
package/dist/react/index.d.cts
CHANGED
|
@@ -1,2 +1,32 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { JunctionClient, AuthSession, Result, AuthUser } from '../index.cjs';
|
|
1
4
|
|
|
2
|
-
|
|
5
|
+
type SessionState = {
|
|
6
|
+
session: AuthSession | null;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
};
|
|
9
|
+
type ContextValue = {
|
|
10
|
+
client: JunctionClient;
|
|
11
|
+
state: SessionState;
|
|
12
|
+
};
|
|
13
|
+
declare function JunctionProvider(props: {
|
|
14
|
+
client: JunctionClient;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}): react.FunctionComponentElement<react.ProviderProps<ContextValue | null>>;
|
|
17
|
+
declare function useJunctionSession(): {
|
|
18
|
+
session: AuthSession | null;
|
|
19
|
+
isLoading: boolean;
|
|
20
|
+
};
|
|
21
|
+
declare function useJunctionUser(): {
|
|
22
|
+
user: AuthUser | null;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
};
|
|
25
|
+
declare function useJunctionAuth(): {
|
|
26
|
+
signIn: (email: string, password: string) => Promise<Result<AuthSession>>;
|
|
27
|
+
signUp: (email: string, password: string) => Promise<Result<AuthSession>>;
|
|
28
|
+
signOut: () => Promise<Result<null>>;
|
|
29
|
+
refreshSession: () => Promise<Result<AuthSession>>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { JunctionProvider, useJunctionAuth, useJunctionSession, useJunctionUser };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,2 +1,32 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { JunctionClient, AuthSession, Result, AuthUser } from '../index.js';
|
|
1
4
|
|
|
2
|
-
|
|
5
|
+
type SessionState = {
|
|
6
|
+
session: AuthSession | null;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
};
|
|
9
|
+
type ContextValue = {
|
|
10
|
+
client: JunctionClient;
|
|
11
|
+
state: SessionState;
|
|
12
|
+
};
|
|
13
|
+
declare function JunctionProvider(props: {
|
|
14
|
+
client: JunctionClient;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}): react.FunctionComponentElement<react.ProviderProps<ContextValue | null>>;
|
|
17
|
+
declare function useJunctionSession(): {
|
|
18
|
+
session: AuthSession | null;
|
|
19
|
+
isLoading: boolean;
|
|
20
|
+
};
|
|
21
|
+
declare function useJunctionUser(): {
|
|
22
|
+
user: AuthUser | null;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
};
|
|
25
|
+
declare function useJunctionAuth(): {
|
|
26
|
+
signIn: (email: string, password: string) => Promise<Result<AuthSession>>;
|
|
27
|
+
signUp: (email: string, password: string) => Promise<Result<AuthSession>>;
|
|
28
|
+
signOut: () => Promise<Result<null>>;
|
|
29
|
+
refreshSession: () => Promise<Result<AuthSession>>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { JunctionProvider, useJunctionAuth, useJunctionSession, useJunctionUser };
|
package/dist/react/index.js
CHANGED
|
@@ -1,4 +1,63 @@
|
|
|
1
1
|
// src/react/index.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
createElement,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useState
|
|
10
|
+
} from "react";
|
|
11
|
+
var JunctionAuthContext = createContext(null);
|
|
12
|
+
function JunctionProvider(props) {
|
|
13
|
+
const { client, children } = props;
|
|
14
|
+
const [state, setState] = useState(() => ({
|
|
15
|
+
session: client.auth.getSession().data?.session ?? null,
|
|
16
|
+
isLoading: true
|
|
17
|
+
}));
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const sub = client.auth.onAuthStateChange((_event, session) => {
|
|
20
|
+
setState({ session, isLoading: false });
|
|
21
|
+
});
|
|
22
|
+
return () => sub.unsubscribe();
|
|
23
|
+
}, [client]);
|
|
24
|
+
const value = useMemo(() => ({ client, state }), [client, state]);
|
|
25
|
+
return createElement(JunctionAuthContext.Provider, { value }, children);
|
|
26
|
+
}
|
|
27
|
+
function useCtx() {
|
|
28
|
+
const ctx = useContext(JunctionAuthContext);
|
|
29
|
+
if (!ctx) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Junction auth hook called outside <JunctionProvider>. Wrap your app in <JunctionProvider client={...}>."
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return ctx;
|
|
35
|
+
}
|
|
36
|
+
function useJunctionSession() {
|
|
37
|
+
const { state } = useCtx();
|
|
38
|
+
return { session: state.session, isLoading: state.isLoading };
|
|
39
|
+
}
|
|
40
|
+
function useJunctionUser() {
|
|
41
|
+
const { state } = useCtx();
|
|
42
|
+
return { user: state.session?.user ?? null, isLoading: state.isLoading };
|
|
43
|
+
}
|
|
44
|
+
function useJunctionAuth() {
|
|
45
|
+
const { client } = useCtx();
|
|
46
|
+
const signIn = useCallback(
|
|
47
|
+
(email, password) => client.auth.signIn({ email, password }),
|
|
48
|
+
[client]
|
|
49
|
+
);
|
|
50
|
+
const signUp = useCallback(
|
|
51
|
+
(email, password) => client.auth.signUp({ email, password }),
|
|
52
|
+
[client]
|
|
53
|
+
);
|
|
54
|
+
const signOut = useCallback(() => client.auth.signOut(), [client]);
|
|
55
|
+
const refreshSession = useCallback(() => client.auth.refreshSession(), [client]);
|
|
56
|
+
return { signIn, signUp, signOut, refreshSession };
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
JunctionProvider,
|
|
60
|
+
useJunctionAuth,
|
|
61
|
+
useJunctionSession,
|
|
62
|
+
useJunctionUser
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onjunctiondev/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Headless auth SDK for Junction — email/password sessions with per-project JWTs and RLS claims.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://onjunction.dev",
|
|
@@ -40,9 +40,17 @@
|
|
|
40
40
|
"check-types": "tsc --noEmit",
|
|
41
41
|
"prepublishOnly": "pnpm build"
|
|
42
42
|
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"react": { "optional": true }
|
|
48
|
+
},
|
|
43
49
|
"devDependencies": {
|
|
44
50
|
"@junction/typescript-config": "workspace:*",
|
|
45
51
|
"@types/node": "26.4.1",
|
|
52
|
+
"@types/react": "^19.0.0",
|
|
53
|
+
"react": "^19.0.0",
|
|
46
54
|
"tsup": "^8.3.5",
|
|
47
55
|
"typescript": "~5.7.0"
|
|
48
56
|
}
|