jazz-react-auth-clerk 0.7.33-unique.2 → 0.7.35-guest-auth.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
1
 
2
- > jazz-react-auth-clerk@0.7.33-new-auth.0 build /Users/anselm/jazz/jazz/packages/jazz-react-auth-clerk
2
+ > jazz-react-auth-clerk@0.7.33-guest-auth.3 build /Users/anselm/jazz/jazz/packages/jazz-react-auth-clerk
3
3
  > npm run lint && rm -rf ./dist && tsc --sourceMap --outDir dist
4
4
 
5
5
 
6
- > jazz-react-auth-clerk@0.7.33-new-auth.0 lint
6
+ > jazz-react-auth-clerk@0.7.33-guest-auth.3 lint
7
7
  > eslint . --ext ts,tsx
8
8
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # jazz-browser-media-images
2
2
 
3
+ ## 0.7.35-guest-auth.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - cojson@0.7.35-guest-auth.5
9
+ - jazz-browser-auth-clerk@0.7.35-guest-auth.5
10
+ - jazz-react@0.7.35-guest-auth.5
11
+ - jazz-tools@0.7.35-guest-auth.5
12
+
13
+ ## 0.7.35-guest-auth.4
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+ - jazz-react@0.7.35-guest-auth.4
19
+ - jazz-tools@0.7.35-guest-auth.4
20
+ - jazz-browser-auth-clerk@0.7.35-guest-auth.4
21
+
22
+ ## 0.7.33-guest-auth.3
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies
27
+ - jazz-react@0.7.35-guest-auth.3
28
+ - jazz-tools@0.7.35-guest-auth.3
29
+ - jazz-browser-auth-clerk@0.7.33-guest-auth.2
30
+
3
31
  ## 0.7.33-unique.2
4
32
 
5
33
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1,48 +1,23 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { SignedOut, SignInButton, useClerk } from "@clerk/clerk-react";
3
1
  import { BrowserClerkAuth } from "jazz-browser-auth-clerk";
4
- import { AuthMethodCtx } from "jazz-react";
5
- import { useState, useMemo, useContext, createContext } from "react";
6
- export const JazzClerkAuthCtx = createContext({
7
- errors: [],
8
- });
9
- export function JazzClerkAuth({ children }) {
10
- const clerk = useClerk();
11
- const [errors, setErrors] = useState([]);
2
+ import { useState, useMemo } from "react";
3
+ export function useJazzClerkAuth(clerk) {
4
+ const [state, setState] = useState({ errors: [] });
12
5
  const authMethod = useMemo(() => {
13
- return new BrowserClerkAuth({
14
- onError: (error) => {
15
- void clerk.signOut();
16
- setErrors((errors) => [...errors, error.toString()]);
17
- },
18
- }, clerk);
19
- }, [clerk]);
20
- return (_jsx(JazzClerkAuthCtx.Provider, { value: { errors }, children: _jsx(AuthMethodCtx.Provider, { value: authMethod, children: children }) }));
6
+ if (clerk.user) {
7
+ return new BrowserClerkAuth({
8
+ onError: (error) => {
9
+ void clerk.signOut();
10
+ setState((state) => ({
11
+ ...state,
12
+ errors: [...state.errors, error.toString()],
13
+ }));
14
+ },
15
+ }, clerk);
16
+ }
17
+ else {
18
+ return undefined;
19
+ }
20
+ }, [clerk.user]);
21
+ return [authMethod, state];
21
22
  }
22
- const JazzClerkBasicUI = ({ appName }) => {
23
- const { errors } = useContext(JazzClerkAuthCtx);
24
- const darkMode = typeof window !== "undefined"
25
- ? window.matchMedia("(prefers-color-scheme: dark)").matches
26
- : false;
27
- return (_jsx(SignedOut, { children: _jsx("div", { style: {
28
- width: "100vw",
29
- height: "100vh",
30
- display: "flex",
31
- alignItems: "center",
32
- justifyContent: "center",
33
- ...(darkMode ? { background: "#000" } : {}),
34
- }, children: _jsxs("div", { style: {
35
- width: "18rem",
36
- display: "flex",
37
- flexDirection: "column",
38
- gap: "2rem",
39
- }, children: [_jsx("h1", { style: {
40
- color: darkMode ? "#fff" : "#000",
41
- textAlign: "center",
42
- }, children: appName }), _jsx(SignInButton, {}), errors.map((error) => (_jsx("div", { style: { color: "red" }, children: error }, error)))] }) }) }));
43
- };
44
- // eslint-disable-next-line @typescript-eslint/no-namespace
45
- (function (JazzClerkAuth) {
46
- JazzClerkAuth.BasicUI = JazzClerkBasicUI;
47
- })(JazzClerkAuth || (JazzClerkAuth = {}));
48
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAa,UAAU,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEhF,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAE1C;IACC,MAAM,EAAE,EAAE;CACb,CAAC,CAAC;AAEH,MAAM,UAAU,aAAa,CAAC,EAAE,QAAQ,EAA2B;IAC/D,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IACzB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAW,EAAE,CAAC,CAAC;IAEnD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE;QAC5B,OAAO,IAAI,gBAAgB,CACvB;YACI,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBACf,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;gBACrB,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;YACzD,CAAC;SACJ,EACD,KAAK,CACR,CAAC;IACN,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,CACH,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE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5C,CAAC,EAFgB,aAAa,KAAb,aAAa,QAE7B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAsB,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE1C,MAAM,UAAU,gBAAgB,CAAC,KAEhC;IACG,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAuB,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAEzE,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE;QAC5B,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YACb,OAAO,IAAI,gBAAgB,CACvB;gBACI,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;oBACf,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;oBACrB,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;wBACjB,GAAG,KAAK;wBACR,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;qBAC9C,CAAC,CAAC,CAAC;gBACR,CAAC;aACJ,EACD,KAAK,CACR,CAAC;QACN,CAAC;aAAM,CAAC;YACJ,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjB,OAAO,CAAC,UAAU,EAAE,KAAK,CAAU,CAAC;AACxC,CAAC"}
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "jazz-react-auth-clerk",
3
- "version": "0.7.33-unique.2",
3
+ "version": "0.7.35-guest-auth.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "src/index.tsx",
7
7
  "license": "MIT",
8
8
  "dependencies": {},
9
9
  "peerDependencies": {
10
- "@clerk/clerk-react": "^4.0.0",
11
10
  "react": "^18.2.0",
12
- "cojson": "0.7.35-unique.2",
13
- "jazz-tools": "0.7.35-unique.2",
14
- "jazz-react": "0.7.35-unique.2",
15
- "jazz-browser-auth-clerk": "0.7.33-unique.1"
11
+ "cojson": "0.7.35-guest-auth.5",
12
+ "jazz-react": "0.7.35-guest-auth.5",
13
+ "jazz-browser-auth-clerk": "0.7.35-guest-auth.5",
14
+ "jazz-tools": "0.7.35-guest-auth.5"
16
15
  },
17
16
  "devDependencies": {
18
17
  "typescript": "^5.1.6",
package/src/index.tsx CHANGED
@@ -1,86 +1,29 @@
1
- import { SignedOut, SignInButton, useClerk } from "@clerk/clerk-react";
2
- import { BrowserClerkAuth } from "jazz-browser-auth-clerk";
3
- import { AuthMethodCtx } from "jazz-react";
4
- import { useState, useMemo, ReactNode, useContext, createContext } from "react";
1
+ import { BrowserClerkAuth, MinimalClerkClient } from "jazz-browser-auth-clerk";
2
+ import { useState, useMemo } from "react";
5
3
 
6
- export const JazzClerkAuthCtx = createContext<{
7
- errors: string[];
8
- }>({
9
- errors: [],
10
- });
11
-
12
- export function JazzClerkAuth({ children }: { children: ReactNode }) {
13
- const clerk = useClerk();
14
- const [errors, setErrors] = useState<string[]>([]);
4
+ export function useJazzClerkAuth(clerk: MinimalClerkClient & {
5
+ signOut: () => Promise<unknown>;
6
+ }) {
7
+ const [state, setState] = useState<{ errors: string[] }>({ errors: [] });
15
8
 
16
9
  const authMethod = useMemo(() => {
17
- return new BrowserClerkAuth(
18
- {
19
- onError: (error) => {
20
- void clerk.signOut();
21
- setErrors((errors) => [...errors, error.toString()]);
10
+ if (clerk.user) {
11
+ return new BrowserClerkAuth(
12
+ {
13
+ onError: (error) => {
14
+ void clerk.signOut();
15
+ setState((state) => ({
16
+ ...state,
17
+ errors: [...state.errors, error.toString()],
18
+ }));
19
+ },
22
20
  },
23
- },
24
- clerk,
25
- );
26
- }, [clerk]);
27
-
28
- return (
29
- <JazzClerkAuthCtx.Provider value={{ errors }}>
30
- <AuthMethodCtx.Provider value={authMethod}>
31
- {children}
32
- </AuthMethodCtx.Provider>
33
- </JazzClerkAuthCtx.Provider>
34
- );
35
- }
36
-
37
- const JazzClerkBasicUI = ({ appName }: { appName: string }) => {
38
- const { errors } = useContext(JazzClerkAuthCtx);
39
- const darkMode =
40
- typeof window !== "undefined"
41
- ? window.matchMedia("(prefers-color-scheme: dark)").matches
42
- : false;
43
- return (
44
- <SignedOut>
45
- <div
46
- style={{
47
- width: "100vw",
48
- height: "100vh",
49
- display: "flex",
50
- alignItems: "center",
51
- justifyContent: "center",
52
- ...(darkMode ? { background: "#000" } : {}),
53
- }}
54
- >
55
- <div
56
- style={{
57
- width: "18rem",
58
- display: "flex",
59
- flexDirection: "column",
60
- gap: "2rem",
61
- }}
62
- >
63
- <h1
64
- style={{
65
- color: darkMode ? "#fff" : "#000",
66
- textAlign: "center",
67
- }}
68
- >
69
- {appName}
70
- </h1>
71
- <SignInButton />
72
- {errors.map((error) => (
73
- <div key={error} style={{ color: "red" }}>
74
- {error}
75
- </div>
76
- ))}
77
- </div>
78
- </div>
79
- </SignedOut>
80
- );
81
- };
21
+ clerk,
22
+ );
23
+ } else {
24
+ return undefined;
25
+ }
26
+ }, [clerk.user]);
82
27
 
83
- // eslint-disable-next-line @typescript-eslint/no-namespace
84
- export namespace JazzClerkAuth {
85
- export const BasicUI = JazzClerkBasicUI;
28
+ return [authMethod, state] as const;
86
29
  }