@workos-inc/authkit-nextjs 0.17.2 → 1.0.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 (55) hide show
  1. package/README.md +102 -25
  2. package/dist/esm/actions.js +11 -0
  3. package/dist/esm/actions.js.map +1 -1
  4. package/dist/esm/components/authkit-provider.js +128 -0
  5. package/dist/esm/components/authkit-provider.js.map +1 -0
  6. package/dist/esm/components/button.js.map +1 -0
  7. package/dist/esm/{impersonation.js → components/impersonation.js} +12 -7
  8. package/dist/esm/components/impersonation.js.map +1 -0
  9. package/dist/esm/components/index.js +4 -0
  10. package/dist/esm/components/index.js.map +1 -0
  11. package/dist/esm/components/min-max-button.js.map +1 -0
  12. package/dist/esm/env-variables.js +5 -2
  13. package/dist/esm/env-variables.js.map +1 -1
  14. package/dist/esm/index.js +4 -8
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/middleware.js +5 -2
  17. package/dist/esm/middleware.js.map +1 -1
  18. package/dist/esm/session.js +104 -107
  19. package/dist/esm/session.js.map +1 -1
  20. package/dist/esm/types/actions.d.ts +6 -0
  21. package/dist/esm/types/components/authkit-provider.d.ts +33 -0
  22. package/dist/esm/types/{impersonation.d.ts → components/impersonation.d.ts} +1 -1
  23. package/dist/esm/types/components/index.d.ts +3 -0
  24. package/dist/esm/types/env-variables.d.ts +2 -2
  25. package/dist/esm/types/index.d.ts +3 -5
  26. package/dist/esm/types/interfaces.d.ts +11 -0
  27. package/dist/esm/types/middleware.d.ts +3 -2
  28. package/dist/esm/types/session.d.ts +5 -28
  29. package/dist/esm/types/workos.d.ts +1 -1
  30. package/dist/esm/workos.js +1 -1
  31. package/dist/esm/workos.js.map +1 -1
  32. package/package.json +11 -1
  33. package/src/actions.ts +20 -0
  34. package/src/components/authkit-provider.tsx +169 -0
  35. package/src/{impersonation.tsx → components/impersonation.tsx} +14 -7
  36. package/src/components/index.ts +4 -0
  37. package/src/env-variables.ts +7 -2
  38. package/src/index.ts +3 -8
  39. package/src/interfaces.ts +13 -0
  40. package/src/middleware.ts +8 -4
  41. package/src/session.ts +137 -124
  42. package/src/workos.ts +1 -1
  43. package/dist/esm/authkit-provider.js +0 -52
  44. package/dist/esm/authkit-provider.js.map +0 -1
  45. package/dist/esm/button.js.map +0 -1
  46. package/dist/esm/impersonation.js.map +0 -1
  47. package/dist/esm/min-max-button.js.map +0 -1
  48. package/dist/esm/types/authkit-provider.d.ts +0 -11
  49. package/src/authkit-provider.tsx +0 -66
  50. /package/dist/esm/{button.js → components/button.js} +0 -0
  51. /package/dist/esm/{min-max-button.js → components/min-max-button.js} +0 -0
  52. /package/dist/esm/types/{button.d.ts → components/button.d.ts} +0 -0
  53. /package/dist/esm/types/{min-max-button.d.ts → components/min-max-button.d.ts} +0 -0
  54. /package/src/{button.tsx → components/button.tsx} +0 -0
  55. /package/src/{min-max-button.tsx → components/min-max-button.tsx} +0 -0
@@ -1,52 +0,0 @@
1
- 'use client';
2
- import * as React from 'react';
3
- import { checkSessionAction } from './actions.js';
4
- export const AuthKitProvider = ({ children, onSessionExpired }) => {
5
- React.useEffect(() => {
6
- // Return early if the session expired checks are disabled.
7
- if (onSessionExpired === false) {
8
- return;
9
- }
10
- let visibilityChangedCalled = false;
11
- const handleVisibilityChange = async () => {
12
- if (visibilityChangedCalled) {
13
- return;
14
- }
15
- // In the case where we're using middleware auth mode, a user that has signed out in a different tab
16
- // will run into an issue if they attempt to hit a server action in the original tab.
17
- // This will force a refresh of the page in that case, which will redirect them to the sign-in page.
18
- if (document.visibilityState === 'visible') {
19
- visibilityChangedCalled = true;
20
- try {
21
- const hasSession = await checkSessionAction();
22
- if (!hasSession) {
23
- throw new Error('Session expired');
24
- }
25
- }
26
- catch (error) {
27
- // 'Failed to fetch' is the error we are looking for if the action fails
28
- // If any other error happens, for other reasons, we should not reload the page
29
- if (error instanceof Error && error.message.includes('Failed to fetch')) {
30
- if (onSessionExpired) {
31
- onSessionExpired();
32
- }
33
- else {
34
- window.location.reload();
35
- }
36
- }
37
- }
38
- finally {
39
- visibilityChangedCalled = false;
40
- }
41
- }
42
- };
43
- window.addEventListener('visibilitychange', handleVisibilityChange);
44
- window.addEventListener('focus', handleVisibilityChange);
45
- return () => {
46
- window.removeEventListener('focus', handleVisibilityChange);
47
- window.removeEventListener('visibilitychange', handleVisibilityChange);
48
- };
49
- }, [onSessionExpired]);
50
- return React.createElement(React.Fragment, null, children);
51
- };
52
- //# sourceMappingURL=authkit-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authkit-provider.js","sourceRoot":"","sources":["../../src/authkit-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAWlD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAwB,EAAE,EAAE;IACtF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,2DAA2D;QAC3D,IAAI,gBAAgB,KAAK,KAAK,EAAE,CAAC;YAC/B,OAAO;QACT,CAAC;QAED,IAAI,uBAAuB,GAAG,KAAK,CAAC;QAEpC,MAAM,sBAAsB,GAAG,KAAK,IAAI,EAAE;YACxC,IAAI,uBAAuB,EAAE,CAAC;gBAC5B,OAAO;YACT,CAAC;YAED,oGAAoG;YACpG,qFAAqF;YACrF,oGAAoG;YACpG,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;gBAC3C,uBAAuB,GAAG,IAAI,CAAC;gBAE/B,IAAI,CAAC;oBACH,MAAM,UAAU,GAAG,MAAM,kBAAkB,EAAE,CAAC;oBAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;wBAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;oBACrC,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,wEAAwE;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AAY,EAAE,aAAa;oBAE3B,UAAU,EAAE,yCAAyC;oBACrD,SAAS,EAAE,gEAAgE;oBAC3E,OAAO,EAAE,qBAAqB;oBAC9B,MAAM,EAAE,qBAAqB;oBAE7B,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;oBAC7C,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;iBACpD;gBAED,oBAAC,YAAY,IAAC,cAAc,EAAC,GAAG,IAAE,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAgB,CACxE,CACF,CACF,CACP,CAAC;AACJ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"min-max-button.js","sourceRoot":"","sources":["../../src/min-max-button.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,MAAM,UAAU,YAAY,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAqB;IAC1E,OAAO,CACL,oBAAC,MAAM,IACL,OAAO,EAAE,GAAG,EAAE;YACZ,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,kCAAkC,CAAuB,CAAC;YAC9F,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAC5D,CAAC,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAEtC,QAAQ,CACF,CACV,CAAC;AACJ,CAAC"}
@@ -1,11 +0,0 @@
1
- import * as React from 'react';
2
- interface AuthKitProviderProps {
3
- children: React.ReactNode;
4
- /**
5
- * Customize what happens when a session is expired. By default,the entire page will be reloaded.
6
- * You can also pass this as `false` to disable the expired session checks.
7
- */
8
- onSessionExpired?: false | (() => void);
9
- }
10
- export declare const AuthKitProvider: ({ children, onSessionExpired }: AuthKitProviderProps) => React.JSX.Element;
11
- export {};
@@ -1,66 +0,0 @@
1
- 'use client';
2
-
3
- import * as React from 'react';
4
- import { checkSessionAction } from './actions.js';
5
-
6
- interface AuthKitProviderProps {
7
- children: React.ReactNode;
8
- /**
9
- * Customize what happens when a session is expired. By default,the entire page will be reloaded.
10
- * You can also pass this as `false` to disable the expired session checks.
11
- */
12
- onSessionExpired?: false | (() => void);
13
- }
14
-
15
- export const AuthKitProvider = ({ children, onSessionExpired }: AuthKitProviderProps) => {
16
- React.useEffect(() => {
17
- // Return early if the session expired checks are disabled.
18
- if (onSessionExpired === false) {
19
- return;
20
- }
21
-
22
- let visibilityChangedCalled = false;
23
-
24
- const handleVisibilityChange = async () => {
25
- if (visibilityChangedCalled) {
26
- return;
27
- }
28
-
29
- // In the case where we're using middleware auth mode, a user that has signed out in a different tab
30
- // will run into an issue if they attempt to hit a server action in the original tab.
31
- // This will force a refresh of the page in that case, which will redirect them to the sign-in page.
32
- if (document.visibilityState === 'visible') {
33
- visibilityChangedCalled = true;
34
-
35
- try {
36
- const hasSession = await checkSessionAction();
37
- if (!hasSession) {
38
- throw new Error('Session expired');
39
- }
40
- } catch (error) {
41
- // 'Failed to fetch' is the error we are looking for if the action fails
42
- // If any other error happens, for other reasons, we should not reload the page
43
- if (error instanceof Error && error.message.includes('Failed to fetch')) {
44
- if (onSessionExpired) {
45
- onSessionExpired();
46
- } else {
47
- window.location.reload();
48
- }
49
- }
50
- } finally {
51
- visibilityChangedCalled = false;
52
- }
53
- }
54
- };
55
-
56
- window.addEventListener('visibilitychange', handleVisibilityChange);
57
- window.addEventListener('focus', handleVisibilityChange);
58
-
59
- return () => {
60
- window.removeEventListener('focus', handleVisibilityChange);
61
- window.removeEventListener('visibilitychange', handleVisibilityChange);
62
- };
63
- }, [onSessionExpired]);
64
-
65
- return <>{children}</>;
66
- };
File without changes
File without changes