@authu/react 0.1.17 → 0.1.27

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.
@@ -1 +1 @@
1
- {"version":3,"file":"AuthUProvider.d.ts","sourceRoot":"","sources":["../src/AuthUProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAgBpB,eAAO,MAAM,YAAY,mDAAgD,CAAC;AAE1E,UAAU,kBAAkB;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAID,wBAAgB,aAAa,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAC,EAAE,kBAAkB,2CAySnE"}
1
+ {"version":3,"file":"AuthUProvider.d.ts","sourceRoot":"","sources":["../src/AuthUProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAgBpB,eAAO,MAAM,YAAY,mDAAgD,CAAC;AAO1E,UAAU,kBAAkB;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAID,wBAAgB,aAAa,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAC,EAAE,kBAAkB,2CA+SnE"}
@@ -2,6 +2,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useEffect, useState, useCallback } from 'react';
3
3
  import { generateCodeVerifier, generateCodeChallenge, generateState, generateNonce, storeCodeVerifier, storeState, storeNonce, getCodeVerifier, getStoredState, clearCodeVerifier, clearState, clearNonce } from './pkce.js';
4
4
  export const AuthUContext = createContext(null);
5
+ function buildBaseUrl(domain) {
6
+ const protocol = domain.startsWith('localhost') ? 'http' : 'https';
7
+ return `${protocol}://${domain}`;
8
+ }
5
9
  const TOKEN_STORAGE_KEY = 'authu_tokens';
6
10
  export function AuthUProvider({ config, children }) {
7
11
  const [state, setState] = useState({
@@ -31,14 +35,14 @@ export function AuthUProvider({ config, children }) {
31
35
  code_challenge: codeChallenge,
32
36
  code_challenge_method: 'S256'
33
37
  });
34
- return `https://${config.domain}/authorize?${params.toString()}`;
38
+ return `${buildBaseUrl(config.domain)}/authorize?${params.toString()}`;
35
39
  }, [config]);
36
40
  const exchangeCodeForTokens = useCallback(async (code) => {
37
41
  const codeVerifier = getCodeVerifier();
38
42
  if (!codeVerifier) {
39
43
  throw new Error('No code verifier found');
40
44
  }
41
- const response = await fetch(`https://${config.domain}/oauth/token`, {
45
+ const response = await fetch(`${buildBaseUrl(config.domain)}/oauth/token`, {
42
46
  method: 'POST',
43
47
  headers: { 'Content-Type': 'application/json' },
44
48
  body: JSON.stringify({
@@ -91,7 +95,7 @@ export function AuthUProvider({ config, children }) {
91
95
  }, []);
92
96
  const fetchUserInfo = useCallback(async (accessToken) => {
93
97
  try {
94
- const response = await fetch(`https://${config.domain}/oauth/userinfo`, {
98
+ const response = await fetch(`${buildBaseUrl(config.domain)}/oauth/userinfo`, {
95
99
  headers: { Authorization: `Bearer ${accessToken}` }
96
100
  });
97
101
  if (!response.ok)
@@ -113,7 +117,7 @@ export function AuthUProvider({ config, children }) {
113
117
  if (!state.refreshToken)
114
118
  return false;
115
119
  try {
116
- const response = await fetch(`https://${config.domain}/oauth/token`, {
120
+ const response = await fetch(`${buildBaseUrl(config.domain)}/oauth/token`, {
117
121
  method: 'POST',
118
122
  headers: { 'Content-Type': 'application/json' },
119
123
  body: JSON.stringify({
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@authu/react",
3
- "version": "0.1.17",
3
+ "version": "0.1.27",
4
4
  "description": "React SDK for AuthU - Centralized Multi-Tenant Authentication Service",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "types": "./dist/index.d.ts",
10
11
  "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
+ "default": "./dist/index.js"
12
13
  }
13
14
  },
14
15
  "files": [