@companyio/auth-react 0.1.8 → 0.1.11
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/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { AuthClient } from '@companyio/auth-client';
|
|
3
|
+
import { AuthSession, User } from '@companyio/auth-contracts';
|
|
4
|
+
type AuthContextValue = {
|
|
5
|
+
client: AuthClient;
|
|
6
|
+
session: AuthSession | null;
|
|
7
|
+
user: User | null;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
signIn: (provider?: string) => Promise<void>;
|
|
10
|
+
signOut: () => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare const AuthProvider: ({ client, children }: PropsWithChildren<{
|
|
13
|
+
client: AuthClient;
|
|
14
|
+
}>) => import("react").JSX.Element;
|
|
15
|
+
export declare const useAuth: () => AuthContextValue;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAE9D,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAIF,eAAO,MAAM,YAAY,GAAI,sBAAsB,iBAAiB,CAAC;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC,gCAoB3F,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,gBAI1B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useState } from 'react';
|
|
3
|
+
const AuthContext = createContext(null);
|
|
4
|
+
export const AuthProvider = ({ client, children }) => {
|
|
5
|
+
const [session, setSession] = useState(client.session);
|
|
6
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const unsubscribe = client.subscribe(setSession);
|
|
9
|
+
void client.restore().finally(() => setIsLoading(false));
|
|
10
|
+
return unsubscribe;
|
|
11
|
+
}, [client]);
|
|
12
|
+
const value = {
|
|
13
|
+
client,
|
|
14
|
+
session,
|
|
15
|
+
user: session?.user ?? null,
|
|
16
|
+
isLoading,
|
|
17
|
+
signIn: (provider) => client.signIn(provider),
|
|
18
|
+
signOut: () => client.signOut(),
|
|
19
|
+
};
|
|
20
|
+
return _jsx(AuthContext.Provider, { value: value, children: children });
|
|
21
|
+
};
|
|
22
|
+
export const useAuth = () => {
|
|
23
|
+
const context = useContext(AuthContext);
|
|
24
|
+
if (!context)
|
|
25
|
+
throw new Error('useAuth must be used inside an AuthProvider.');
|
|
26
|
+
return context;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,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package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@companyio/auth-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "React provider and hooks for the shared authentication platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@companyio/auth-client": "0.1.
|
|
20
|
-
"@companyio/auth-contracts": "0.1.
|
|
19
|
+
"@companyio/auth-client": "0.1.11",
|
|
20
|
+
"@companyio/auth-contracts": "0.1.11"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"react": "^18.2.0 || ^19.0.0"
|