next-auth-heksso 1.0.5 → 1.0.7

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.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -5,14 +5,14 @@
5
5
  "email": "contact@voakie.com"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "1.0.5",
8
+ "version": "1.0.7",
9
9
  "scripts": {
10
- "prepublish": "rm lib/ -r && tsc",
10
+ "prepublish": "rm api/ -r && rm react/ -r && tsc",
11
11
  "build": "tsc",
12
- "clean": "rm lib/ -r"
12
+ "clean": "rm api/ -r && rm react/ -r -r"
13
13
  },
14
- "main": "lib/index.js",
15
- "types": "lib/index.d.ts",
14
+ "main": "api/index.js",
15
+ "types": "api/index.d.ts",
16
16
  "dependencies": {
17
17
  "@types/node": "^18.11.18",
18
18
  "@types/react": "^18.0.27",
@@ -24,15 +24,5 @@
24
24
  "react": "^18.2.0",
25
25
  "react-dom": "^18.2.0",
26
26
  "typescript": "^4.9.4"
27
- },
28
- "exports": {
29
- "./api": {
30
- "import": "./lib/api/index.js",
31
- "types": "./lib/api/index.d.ts"
32
- },
33
- "./react": {
34
- "import": "./lib/react/index.js",
35
- "types": "./lib/react/index.d.ts"
36
- }
37
27
  }
38
28
  }
@@ -1,5 +1,7 @@
1
1
  import React, { ReactNode } from "react";
2
2
  export interface KeycloakSession {
3
+ isAuthenticated: boolean;
4
+ accessTokenError: boolean;
3
5
  getAccessToken: () => Promise<string>;
4
6
  }
5
7
  export declare const KeycloakSessionContext: React.Context<KeycloakSession>;
@@ -37,6 +37,8 @@ const react_1 = require("next-auth/react");
37
37
  const router_1 = require("next/router");
38
38
  const react_2 = __importStar(require("react"));
39
39
  exports.KeycloakSessionContext = (0, react_2.createContext)({
40
+ isAuthenticated: false,
41
+ accessTokenError: false,
40
42
  getAccessToken: () => __awaiter(void 0, void 0, void 0, function* () {
41
43
  return "";
42
44
  })
@@ -97,6 +99,9 @@ function KeycloakSessionProvider(props) {
97
99
  else
98
100
  return accessToken;
99
101
  }), [accessToken, accessTokenExpires]);
102
+ const isAuthenticated = (0, react_2.useMemo)(() => {
103
+ return typeof accessToken === "string" && accessToken.length > 0;
104
+ }, [accessToken]);
100
105
  // Because this component is present on every page that requires a session,
101
106
  // we check for a valid refresh token here
102
107
  (0, react_2.useEffect)(() => {
@@ -118,6 +123,6 @@ function KeycloakSessionProvider(props) {
118
123
  setAccessTokenExpires(undefined);
119
124
  }
120
125
  }, [session, router.pathname, accessToken, router, props.signInPage, accessTokenError]);
121
- return (react_2.default.createElement(exports.KeycloakSessionContext.Provider, { value: { getAccessToken } }, props.children));
126
+ return (react_2.default.createElement(exports.KeycloakSessionContext.Provider, { value: { getAccessToken, isAuthenticated, accessTokenError } }, props.children));
122
127
  }
123
128
  exports.KeycloakSessionProvider = KeycloakSessionProvider;
File without changes
File without changes
@@ -1,12 +1,16 @@
1
1
  import { signOut, useSession } from "next-auth/react"
2
2
  import { useRouter } from "next/router"
3
- import React, { createContext, ReactNode, useCallback, useEffect, useState } from "react"
3
+ import React, { createContext, ReactNode, useCallback, useEffect, useMemo, useState } from "react"
4
4
 
5
5
  export interface KeycloakSession {
6
+ isAuthenticated: boolean
7
+ accessTokenError: boolean
6
8
  getAccessToken: () => Promise<string>
7
9
  }
8
10
 
9
11
  export const KeycloakSessionContext = createContext<KeycloakSession>({
12
+ isAuthenticated: false,
13
+ accessTokenError: false,
10
14
  getAccessToken: async () => {
11
15
  return ""
12
16
  }
@@ -71,6 +75,10 @@ export function KeycloakSessionProvider(props: {
71
75
  } else return accessToken
72
76
  }, [accessToken, accessTokenExpires])
73
77
 
78
+ const isAuthenticated = useMemo(() => {
79
+ return typeof accessToken === "string" && accessToken.length > 0
80
+ }, [accessToken])
81
+
74
82
  // Because this component is present on every page that requires a session,
75
83
  // we check for a valid refresh token here
76
84
  useEffect(() => {
@@ -95,7 +103,7 @@ export function KeycloakSessionProvider(props: {
95
103
 
96
104
  return (
97
105
  <KeycloakSessionContext.Provider
98
- value={{ getAccessToken }}
106
+ value={{ getAccessToken, isAuthenticated, accessTokenError }}
99
107
  >
100
108
  {props.children}
101
109
  </KeycloakSessionContext.Provider>
package/tsconfig.json CHANGED
@@ -49,7 +49,7 @@
49
49
  // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
50
50
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
51
51
  // "outFile": "./lib/index.js", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
52
- "outDir": "./lib", /* Specify an output folder for all emitted files. */
52
+ "outDir": ".", /* Specify an output folder for all emitted files. */
53
53
  // "removeComments": true, /* Disable emitting comments. */
54
54
  // "noEmit": true, /* Disable emitting files from a compilation. */
55
55
  // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
package/lib/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./api";
package/lib/index.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./api"), exports);
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./api"