@beamarco/auth-sdk 0.1.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.
Files changed (41) hide show
  1. package/README.md +163 -0
  2. package/dist/client.d.ts +59 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +149 -0
  5. package/dist/components/ProtectedRoute.d.ts +13 -0
  6. package/dist/components/ProtectedRoute.d.ts.map +1 -0
  7. package/dist/components/ProtectedRoute.js +21 -0
  8. package/dist/components/SignIn.d.ts +87 -0
  9. package/dist/components/SignIn.d.ts.map +1 -0
  10. package/dist/components/SignIn.js +149 -0
  11. package/dist/components/SignInButton.d.ts +13 -0
  12. package/dist/components/SignInButton.d.ts.map +1 -0
  13. package/dist/components/SignInButton.js +14 -0
  14. package/dist/components/SignUp.d.ts +79 -0
  15. package/dist/components/SignUp.d.ts.map +1 -0
  16. package/dist/components/SignUp.js +143 -0
  17. package/dist/components/SignUpButton.d.ts +13 -0
  18. package/dist/components/SignUpButton.d.ts.map +1 -0
  19. package/dist/components/SignUpButton.js +14 -0
  20. package/dist/components/SignedIn.d.ts +9 -0
  21. package/dist/components/SignedIn.d.ts.map +1 -0
  22. package/dist/components/SignedIn.js +13 -0
  23. package/dist/components/SignedOut.d.ts +9 -0
  24. package/dist/components/SignedOut.d.ts.map +1 -0
  25. package/dist/components/SignedOut.js +13 -0
  26. package/dist/components/UserButton.d.ts +13 -0
  27. package/dist/components/UserButton.d.ts.map +1 -0
  28. package/dist/components/UserButton.js +64 -0
  29. package/dist/context.d.ts +29 -0
  30. package/dist/context.d.ts.map +1 -0
  31. package/dist/context.js +88 -0
  32. package/dist/hooks.d.ts +13 -0
  33. package/dist/hooks.d.ts.map +1 -0
  34. package/dist/hooks.js +22 -0
  35. package/dist/index.d.ts +48 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +46 -0
  38. package/dist/types.d.ts +61 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +8 -0
  41. package/package.json +56 -0
@@ -0,0 +1,79 @@
1
+ import React from 'react';
2
+ import type { RegisterCredentials } from '../types';
3
+ declare const defaultStyles: {
4
+ container: {
5
+ display: string;
6
+ flexDirection: "column";
7
+ gap: string;
8
+ maxWidth: string;
9
+ padding: string;
10
+ fontFamily: string;
11
+ };
12
+ input: {
13
+ padding: string;
14
+ fontSize: string;
15
+ border: string;
16
+ borderRadius: string;
17
+ width: string;
18
+ boxSizing: "border-box";
19
+ };
20
+ button: {
21
+ padding: string;
22
+ fontSize: string;
23
+ fontWeight: number;
24
+ border: string;
25
+ borderRadius: string;
26
+ cursor: string;
27
+ backgroundColor: string;
28
+ color: string;
29
+ };
30
+ buttonGoogle: {
31
+ padding: string;
32
+ fontSize: string;
33
+ border: string;
34
+ borderRadius: string;
35
+ cursor: string;
36
+ backgroundColor: string;
37
+ color: string;
38
+ };
39
+ error: {
40
+ color: string;
41
+ fontSize: string;
42
+ };
43
+ link: {
44
+ color: string;
45
+ cursor: string;
46
+ textDecoration: string;
47
+ };
48
+ divider: {
49
+ display: string;
50
+ alignItems: string;
51
+ gap: string;
52
+ color: string;
53
+ };
54
+ dividerLine: {
55
+ flex: number;
56
+ height: number;
57
+ backgroundColor: string;
58
+ };
59
+ };
60
+ export interface SignUpProps {
61
+ afterSignUpUrl?: string;
62
+ styles?: Partial<typeof defaultStyles>;
63
+ showGoogle?: boolean;
64
+ signInUrl?: string;
65
+ onSuccess?: () => void;
66
+ children?: (props: SignUpRenderProps) => React.ReactNode;
67
+ }
68
+ export interface SignUpRenderProps {
69
+ signUp: (credentials: RegisterCredentials) => Promise<void>;
70
+ signUpWithGoogle: (credential: {
71
+ credential: string;
72
+ clientId: string;
73
+ }) => Promise<void>;
74
+ error: string | null;
75
+ isLoading: boolean;
76
+ }
77
+ export declare function SignUp({ afterSignUpUrl, styles: customStyles, showGoogle, signInUrl, onSuccess, children, }: SignUpProps): import("react/jsx-runtime").JSX.Element;
78
+ export {};
79
+ //# sourceMappingURL=SignUp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignUp.d.ts","sourceRoot":"","sources":["../../src/components/SignUp.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnD,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDlB,CAAA;AAED,MAAM,WAAW,WAAW;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC,OAAO,aAAa,CAAC,CAAA;IACtC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,KAAK,CAAC,SAAS,CAAA;CACzD;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,CAAC,WAAW,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3D,gBAAgB,EAAE,CAAC,UAAU,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACzF,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;CACnB;AAoCD,wBAAgB,MAAM,CAAC,EACrB,cAAoB,EACpB,MAAM,EAAE,YAAiB,EACzB,UAAiB,EACjB,SAAsB,EACtB,SAAS,EACT,QAAQ,GACT,EAAE,WAAW,2CAgHb"}
@@ -0,0 +1,143 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React, { useState } from 'react';
3
+ import { useBeamarAuth } from '../hooks';
4
+ const defaultStyles = {
5
+ container: {
6
+ display: 'flex',
7
+ flexDirection: 'column',
8
+ gap: '16px',
9
+ maxWidth: '400px',
10
+ padding: '24px',
11
+ fontFamily: 'system-ui, sans-serif',
12
+ },
13
+ input: {
14
+ padding: '10px 12px',
15
+ fontSize: '16px',
16
+ border: '1px solid #ccc',
17
+ borderRadius: '6px',
18
+ width: '100%',
19
+ boxSizing: 'border-box',
20
+ },
21
+ button: {
22
+ padding: '12px 24px',
23
+ fontSize: '16px',
24
+ fontWeight: 600,
25
+ border: 'none',
26
+ borderRadius: '6px',
27
+ cursor: 'pointer',
28
+ backgroundColor: '#0066cc',
29
+ color: 'white',
30
+ },
31
+ buttonGoogle: {
32
+ padding: '12px 24px',
33
+ fontSize: '16px',
34
+ border: '1px solid #ccc',
35
+ borderRadius: '6px',
36
+ cursor: 'pointer',
37
+ backgroundColor: 'white',
38
+ color: '#333',
39
+ },
40
+ error: {
41
+ color: '#c00',
42
+ fontSize: '14px',
43
+ },
44
+ link: {
45
+ color: '#0066cc',
46
+ cursor: 'pointer',
47
+ textDecoration: 'none',
48
+ },
49
+ divider: {
50
+ display: 'flex',
51
+ alignItems: 'center',
52
+ gap: '12px',
53
+ color: '#666',
54
+ },
55
+ dividerLine: {
56
+ flex: 1,
57
+ height: 1,
58
+ backgroundColor: '#ddd',
59
+ },
60
+ };
61
+ function GoogleSignUpButton({ onSuccess, disabled, clientId, }) {
62
+ const [GoogleLogin, setGoogleLogin] = useState(null);
63
+ React.useEffect(() => {
64
+ import('@react-oauth/google').then((mod) => {
65
+ setGoogleLogin(() => mod.GoogleLogin);
66
+ });
67
+ }, []);
68
+ if (!clientId || !GoogleLogin)
69
+ return null;
70
+ return (_jsx(GoogleLogin, { onSuccess: (res) => {
71
+ if (res.credential && res.clientId) {
72
+ onSuccess({ credential: res.credential, clientId: res.clientId });
73
+ }
74
+ }, onError: () => { } }));
75
+ }
76
+ export function SignUp({ afterSignUpUrl = '/', styles: customStyles = {}, showGoogle = true, signInUrl = '/sign-in', onSuccess, children, }) {
77
+ const { signUp, signUpWithGoogle, googleClientId } = useBeamarAuth();
78
+ const [email, setEmail] = useState('');
79
+ const [password, setPassword] = useState('');
80
+ const [error, setError] = useState(null);
81
+ const [isLoading, setIsLoading] = useState(false);
82
+ const styles = { ...defaultStyles, ...customStyles };
83
+ const handleSubmit = async (e) => {
84
+ e.preventDefault();
85
+ setError(null);
86
+ setIsLoading(true);
87
+ try {
88
+ await signUp({ email, password });
89
+ onSuccess?.();
90
+ if (afterSignUpUrl) {
91
+ window.location.href = afterSignUpUrl;
92
+ }
93
+ }
94
+ catch (err) {
95
+ setError(err instanceof Error ? err.message : 'Sign up failed');
96
+ }
97
+ finally {
98
+ setIsLoading(false);
99
+ }
100
+ };
101
+ const handleGoogleSuccess = async (credential) => {
102
+ setError(null);
103
+ setIsLoading(true);
104
+ try {
105
+ await signUpWithGoogle(credential);
106
+ onSuccess?.();
107
+ if (afterSignUpUrl) {
108
+ window.location.href = afterSignUpUrl;
109
+ }
110
+ }
111
+ catch (err) {
112
+ setError(err instanceof Error ? err.message : 'Sign up with Google failed');
113
+ }
114
+ finally {
115
+ setIsLoading(false);
116
+ }
117
+ };
118
+ if (children) {
119
+ return (_jsx(_Fragment, { children: children({
120
+ signUp: async (creds) => {
121
+ setError(null);
122
+ setIsLoading(true);
123
+ try {
124
+ await signUp(creds);
125
+ onSuccess?.();
126
+ if (afterSignUpUrl)
127
+ window.location.href = afterSignUpUrl;
128
+ }
129
+ catch (err) {
130
+ setError(err instanceof Error ? err.message : 'Sign up failed');
131
+ throw err;
132
+ }
133
+ finally {
134
+ setIsLoading(false);
135
+ }
136
+ },
137
+ signUpWithGoogle: handleGoogleSuccess,
138
+ error,
139
+ isLoading,
140
+ }) }));
141
+ }
142
+ return (_jsxs("form", { onSubmit: handleSubmit, style: styles.container, children: [error && _jsx("div", { style: styles.error, children: error }), _jsx("input", { type: "email", placeholder: "Email", value: email, onChange: (e) => setEmail(e.target.value), required: true, disabled: isLoading, style: styles.input }), _jsx("input", { type: "password", placeholder: "Password", value: password, onChange: (e) => setPassword(e.target.value), required: true, disabled: isLoading, minLength: 6, style: styles.input }), _jsx("button", { type: "submit", disabled: isLoading, style: styles.button, children: isLoading ? 'Creating account...' : 'Sign up' }), showGoogle && (_jsxs(_Fragment, { children: [_jsxs("div", { style: styles.divider, children: [_jsx("span", { style: styles.dividerLine }), _jsx("span", { children: "or" }), _jsx("span", { style: styles.dividerLine })] }), _jsx(GoogleSignUpButton, { onSuccess: handleGoogleSuccess, disabled: isLoading, clientId: googleClientId })] })), _jsxs("p", { children: ["Already have an account? ", _jsx("a", { href: signInUrl, style: styles.link, children: "Sign in" })] })] }));
143
+ }
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ export interface SignUpButtonProps {
3
+ children?: React.ReactNode;
4
+ signUpUrl?: string;
5
+ fallbackRedirectUrl?: string;
6
+ style?: React.CSSProperties;
7
+ className?: string;
8
+ }
9
+ /**
10
+ * Button that redirects to sign-up page
11
+ */
12
+ export declare function SignUpButton({ children, signUpUrl, fallbackRedirectUrl, style, className, }: SignUpButtonProps): import("react/jsx-runtime").JSX.Element | null;
13
+ //# sourceMappingURL=SignUpButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignUpButton.d.ts","sourceRoot":"","sources":["../../src/components/SignUpButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAoB,EACpB,SAAsB,EACtB,mBAAmB,EACnB,KAAK,EACL,SAAS,GACV,EAAE,iBAAiB,kDAanB"}
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useBeamarAuth } from '../hooks';
3
+ /**
4
+ * Button that redirects to sign-up page
5
+ */
6
+ export function SignUpButton({ children = 'Sign up', signUpUrl = '/sign-up', fallbackRedirectUrl, style, className, }) {
7
+ const { isSignedIn } = useBeamarAuth();
8
+ const to = fallbackRedirectUrl
9
+ ? `${signUpUrl}?redirect_url=${encodeURIComponent(fallbackRedirectUrl)}`
10
+ : signUpUrl;
11
+ if (isSignedIn)
12
+ return null;
13
+ return (_jsx("a", { href: to, style: style, className: className, children: children }));
14
+ }
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export interface SignedInProps {
3
+ children: React.ReactNode;
4
+ }
5
+ /**
6
+ * Renders children only when user is signed in
7
+ */
8
+ export declare function SignedIn({ children }: SignedInProps): import("react/jsx-runtime").JSX.Element | null;
9
+ //# sourceMappingURL=SignedIn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignedIn.d.ts","sourceRoot":"","sources":["../../src/components/SignedIn.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,aAAa,kDAKnD"}
@@ -0,0 +1,13 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useBeamarAuth } from '../hooks';
3
+ /**
4
+ * Renders children only when user is signed in
5
+ */
6
+ export function SignedIn({ children }) {
7
+ const { isLoaded, isSignedIn } = useBeamarAuth();
8
+ if (!isLoaded)
9
+ return null;
10
+ if (!isSignedIn)
11
+ return null;
12
+ return _jsx(_Fragment, { children: children });
13
+ }
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export interface SignedOutProps {
3
+ children: React.ReactNode;
4
+ }
5
+ /**
6
+ * Renders children only when user is signed out
7
+ */
8
+ export declare function SignedOut({ children }: SignedOutProps): import("react/jsx-runtime").JSX.Element | null;
9
+ //# sourceMappingURL=SignedOut.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignedOut.d.ts","sourceRoot":"","sources":["../../src/components/SignedOut.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE,cAAc,kDAKrD"}
@@ -0,0 +1,13 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useBeamarAuth } from '../hooks';
3
+ /**
4
+ * Renders children only when user is signed out
5
+ */
6
+ export function SignedOut({ children }) {
7
+ const { isLoaded, isSignedIn } = useBeamarAuth();
8
+ if (!isLoaded)
9
+ return null;
10
+ if (isSignedIn)
11
+ return null;
12
+ return _jsx(_Fragment, { children: children });
13
+ }
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ export interface UserButtonProps {
3
+ children?: React.ReactNode;
4
+ /** Custom dropdown content */
5
+ fallback?: React.ReactNode;
6
+ style?: React.CSSProperties;
7
+ className?: string;
8
+ }
9
+ /**
10
+ * User menu button - shows user email/avatar, dropdown with sign out
11
+ */
12
+ export declare function UserButton({ children, fallback, style, className }: UserButtonProps): import("react/jsx-runtime").JSX.Element | null;
13
+ //# sourceMappingURL=UserButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserButton.d.ts","sourceRoot":"","sources":["../../src/components/UserButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAGvC,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,eAAe,kDA2GnF"}
@@ -0,0 +1,64 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { useBeamarAuth } from '../hooks';
4
+ /**
5
+ * User menu button - shows user email/avatar, dropdown with sign out
6
+ */
7
+ export function UserButton({ children, fallback, style, className }) {
8
+ const { user, signOut, isLoaded } = useBeamarAuth();
9
+ const [open, setOpen] = useState(false);
10
+ if (!isLoaded)
11
+ return null;
12
+ if (!user)
13
+ return _jsx(_Fragment, { children: fallback });
14
+ const defaultTrigger = (_jsxs("button", { type: "button", onClick: () => setOpen(!open), style: {
15
+ display: 'flex',
16
+ alignItems: 'center',
17
+ gap: '8px',
18
+ padding: '8px 12px',
19
+ border: '1px solid #ccc',
20
+ borderRadius: '6px',
21
+ backgroundColor: 'white',
22
+ cursor: 'pointer',
23
+ ...style,
24
+ }, className: className, children: [user.imageUrl ? (_jsx("img", { src: user.imageUrl, alt: "", style: { width: 24, height: 24, borderRadius: '50%' } })) : (_jsx("div", { style: {
25
+ width: 24,
26
+ height: 24,
27
+ borderRadius: '50%',
28
+ backgroundColor: '#0066cc',
29
+ color: 'white',
30
+ display: 'flex',
31
+ alignItems: 'center',
32
+ justifyContent: 'center',
33
+ fontSize: 12,
34
+ }, children: (user.displayName || user.loginId || '?')[0].toUpperCase() })), _jsx("span", { children: user.displayName || user.loginId })] }));
35
+ return (_jsxs("div", { style: { position: 'relative' }, children: [children ?? defaultTrigger, open && (_jsxs(_Fragment, { children: [_jsx("div", { style: {
36
+ position: 'fixed',
37
+ inset: 0,
38
+ zIndex: 999,
39
+ }, onClick: () => setOpen(false) }), _jsxs("div", { style: {
40
+ position: 'absolute',
41
+ top: '100%',
42
+ right: 0,
43
+ marginTop: 4,
44
+ padding: '8px',
45
+ backgroundColor: 'white',
46
+ border: '1px solid #ddd',
47
+ borderRadius: '6px',
48
+ boxShadow: '0 4px 12px rgba(0,0,0,0.15)',
49
+ zIndex: 1000,
50
+ minWidth: 180,
51
+ }, children: [_jsxs("div", { style: { padding: '8px', borderBottom: '1px solid #eee' }, children: [_jsx("div", { style: { fontWeight: 600 }, children: user.displayName || user.loginId }), _jsx("div", { style: { fontSize: 12, color: '#666' }, children: user.loginId })] }), _jsx("button", { type: "button", onClick: () => {
52
+ signOut();
53
+ setOpen(false);
54
+ }, style: {
55
+ width: '100%',
56
+ padding: '8px 12px',
57
+ marginTop: 4,
58
+ textAlign: 'left',
59
+ border: 'none',
60
+ backgroundColor: 'transparent',
61
+ cursor: 'pointer',
62
+ color: '#c00',
63
+ }, children: "Sign out" })] })] }))] }));
64
+ }
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { BeamarAuthClient } from './client';
3
+ import type { User, BeamarAuthConfig, LoginCredentials, RegisterCredentials, GoogleCredential } from './types';
4
+ export interface AuthContextValue {
5
+ isLoaded: boolean;
6
+ isSignedIn: boolean;
7
+ user: User | null;
8
+ signIn: (credentials: LoginCredentials) => Promise<void>;
9
+ signUp: (credentials: RegisterCredentials) => Promise<void>;
10
+ signOut: () => Promise<void>;
11
+ signInWithGoogle: (credential: GoogleCredential) => Promise<void>;
12
+ signUpWithGoogle: (credential: GoogleCredential) => Promise<void>;
13
+ getToken: () => Promise<string | null>;
14
+ refreshSession: () => Promise<User | null>;
15
+ client: BeamarAuthClient;
16
+ /** Google OAuth client ID if configured */
17
+ googleClientId?: string;
18
+ }
19
+ declare const AuthContext: React.Context<AuthContextValue | null>;
20
+ export interface BeamarAuthProviderProps {
21
+ config: BeamarAuthConfig;
22
+ children: React.ReactNode;
23
+ }
24
+ /**
25
+ * BeamarAuthProvider - wrap your app to enable auth
26
+ */
27
+ export declare function BeamarAuthProvider({ config, children }: BeamarAuthProviderProps): import("react/jsx-runtime").JSX.Element;
28
+ export { AuthContext };
29
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0D,MAAM,OAAO,CAAA;AAE9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE9G,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;IACjB,MAAM,EAAE,CAAC,WAAW,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,MAAM,EAAE,CAAC,WAAW,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3D,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,gBAAgB,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACjE,gBAAgB,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACjE,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;IACtC,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;IAC1C,MAAM,EAAE,gBAAgB,CAAA;IACxB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,QAAA,MAAM,WAAW,wCAA+C,CAAA;AAEhE,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,gBAAgB,CAAA;IACxB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,uBAAuB,2CA+G/E;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
@@ -0,0 +1,88 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { createContext, useCallback, useEffect, useState } from 'react';
3
+ import { GoogleOAuthProvider } from '@react-oauth/google';
4
+ import { BeamarAuthClient } from './client';
5
+ const AuthContext = createContext(null);
6
+ /**
7
+ * BeamarAuthProvider - wrap your app to enable auth
8
+ */
9
+ export function BeamarAuthProvider({ config, children }) {
10
+ const [user, setUser] = useState(null);
11
+ const [isLoaded, setIsLoaded] = useState(false);
12
+ const client = React.useMemo(() => new BeamarAuthClient({
13
+ apiUrl: config.apiUrl,
14
+ appName: config.appName,
15
+ parentUrl: config.parentUrl,
16
+ }), [config.apiUrl, config.appName, config.parentUrl]);
17
+ const refreshSession = useCallback(async () => {
18
+ const u = await client.getSession();
19
+ setUser(u);
20
+ return u;
21
+ }, [client]);
22
+ useEffect(() => {
23
+ let cancelled = false;
24
+ client
25
+ .getSession()
26
+ .then((u) => {
27
+ if (!cancelled) {
28
+ setUser(u);
29
+ }
30
+ })
31
+ .finally(() => {
32
+ if (!cancelled) {
33
+ setIsLoaded(true);
34
+ }
35
+ });
36
+ return () => {
37
+ cancelled = true;
38
+ };
39
+ }, [client]);
40
+ const signIn = useCallback(async (credentials) => {
41
+ const u = await client.login(credentials);
42
+ setUser(u);
43
+ }, [client]);
44
+ const signUp = useCallback(async (credentials) => {
45
+ await client.register(credentials);
46
+ const u = await client.getSession();
47
+ setUser(u);
48
+ }, [client]);
49
+ const signOut = useCallback(async () => {
50
+ await client.logout();
51
+ setUser(null);
52
+ }, [client]);
53
+ const signInWithGoogle = useCallback(async (credential) => {
54
+ const u = await client.loginWithGoogle(credential);
55
+ setUser(u);
56
+ }, [client]);
57
+ const signUpWithGoogle = useCallback(async (credential) => {
58
+ await client.registerWithGoogle(credential);
59
+ const u = await client.getSession();
60
+ setUser(u);
61
+ }, [client]);
62
+ const getToken = useCallback(async () => {
63
+ // Cookie is httpOnly - we can't read it from JS.
64
+ // For API calls, the browser sends it automatically with credentials: 'include'.
65
+ // Return null - callers should use fetch with credentials: 'include' to the auth backend.
66
+ return null;
67
+ }, []);
68
+ const value = {
69
+ isLoaded,
70
+ isSignedIn: !!user,
71
+ user,
72
+ signIn,
73
+ signUp,
74
+ signOut,
75
+ signInWithGoogle,
76
+ signUpWithGoogle,
77
+ getToken,
78
+ refreshSession,
79
+ client,
80
+ googleClientId: config.googleClientId,
81
+ };
82
+ const content = _jsx(AuthContext.Provider, { value: value, children: children });
83
+ if (config.googleClientId) {
84
+ return (_jsx(GoogleOAuthProvider, { clientId: config.googleClientId, children: content }));
85
+ }
86
+ return content;
87
+ }
88
+ export { AuthContext };
@@ -0,0 +1,13 @@
1
+ export declare function useBeamarAuth(): import("./context").AuthContextValue;
2
+ /**
3
+ * Alias for useBeamarAuth - Clerk-style naming
4
+ */
5
+ export declare function useAuth(): import("./context").AuthContextValue;
6
+ /**
7
+ * Get current user - returns null if not signed in
8
+ */
9
+ export declare function useUser(): {
10
+ user: import("./types").User | null;
11
+ isLoaded: boolean;
12
+ };
13
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,yCAM5B;AAED;;GAEG;AACH,wBAAgB,OAAO,yCAEtB;AAED;;GAEG;AACH,wBAAgB,OAAO;;;EAGtB"}
package/dist/hooks.js ADDED
@@ -0,0 +1,22 @@
1
+ import { useContext } from 'react';
2
+ import { AuthContext } from './context';
3
+ export function useBeamarAuth() {
4
+ const ctx = useContext(AuthContext);
5
+ if (!ctx) {
6
+ throw new Error('useBeamarAuth must be used within BeamarAuthProvider');
7
+ }
8
+ return ctx;
9
+ }
10
+ /**
11
+ * Alias for useBeamarAuth - Clerk-style naming
12
+ */
13
+ export function useAuth() {
14
+ return useBeamarAuth();
15
+ }
16
+ /**
17
+ * Get current user - returns null if not signed in
18
+ */
19
+ export function useUser() {
20
+ const { user, isLoaded } = useBeamarAuth();
21
+ return { user, isLoaded };
22
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @beamarco/auth-sdk - Embed authentication like Clerk in your React apps
3
+ *
4
+ * @example
5
+ * ```tsx
6
+ * import {
7
+ * BeamarAuthProvider,
8
+ * SignIn,
9
+ * SignUp,
10
+ * SignedIn,
11
+ * SignedOut,
12
+ * useAuth,
13
+ * } from '@beamarco/auth-sdk'
14
+ *
15
+ * const config = {
16
+ * apiUrl: 'https://auth.creztu.com',
17
+ * appName: 'my-app',
18
+ * googleClientId: 'xxx.apps.googleusercontent.com',
19
+ * }
20
+ *
21
+ * function App() {
22
+ * return (
23
+ * <BeamarAuthProvider config={config}>
24
+ * <SignedIn>
25
+ * <Dashboard />
26
+ * </SignedIn>
27
+ * <SignedOut>
28
+ * <SignIn />
29
+ * </SignedOut>
30
+ * </BeamarAuthProvider>
31
+ * )
32
+ * }
33
+ * ```
34
+ */
35
+ export { BeamarAuthProvider, AuthContext } from './context';
36
+ export { useBeamarAuth, useAuth, useUser } from './hooks';
37
+ export { BeamarAuthClient } from './client';
38
+ export { SignIn } from './components/SignIn';
39
+ export { SignUp } from './components/SignUp';
40
+ export { SignedIn } from './components/SignedIn';
41
+ export { SignedOut } from './components/SignedOut';
42
+ export { SignInButton } from './components/SignInButton';
43
+ export { SignUpButton } from './components/SignUpButton';
44
+ export { UserButton } from './components/UserButton';
45
+ export { ProtectedRoute } from './components/ProtectedRoute';
46
+ export type { User, TenantMember, BeamarAuthConfig, LoginCredentials, RegisterCredentials, GoogleCredential, } from './types';
47
+ export { AuthError } from './types';
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D,YAAY,EACV,IAAI,EACJ,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @beamarco/auth-sdk - Embed authentication like Clerk in your React apps
3
+ *
4
+ * @example
5
+ * ```tsx
6
+ * import {
7
+ * BeamarAuthProvider,
8
+ * SignIn,
9
+ * SignUp,
10
+ * SignedIn,
11
+ * SignedOut,
12
+ * useAuth,
13
+ * } from '@beamarco/auth-sdk'
14
+ *
15
+ * const config = {
16
+ * apiUrl: 'https://auth.creztu.com',
17
+ * appName: 'my-app',
18
+ * googleClientId: 'xxx.apps.googleusercontent.com',
19
+ * }
20
+ *
21
+ * function App() {
22
+ * return (
23
+ * <BeamarAuthProvider config={config}>
24
+ * <SignedIn>
25
+ * <Dashboard />
26
+ * </SignedIn>
27
+ * <SignedOut>
28
+ * <SignIn />
29
+ * </SignedOut>
30
+ * </BeamarAuthProvider>
31
+ * )
32
+ * }
33
+ * ```
34
+ */
35
+ export { BeamarAuthProvider, AuthContext } from './context';
36
+ export { useBeamarAuth, useAuth, useUser } from './hooks';
37
+ export { BeamarAuthClient } from './client';
38
+ export { SignIn } from './components/SignIn';
39
+ export { SignUp } from './components/SignUp';
40
+ export { SignedIn } from './components/SignedIn';
41
+ export { SignedOut } from './components/SignedOut';
42
+ export { SignInButton } from './components/SignInButton';
43
+ export { SignUpButton } from './components/SignUpButton';
44
+ export { UserButton } from './components/UserButton';
45
+ export { ProtectedRoute } from './components/ProtectedRoute';
46
+ export { AuthError } from './types';