@spidy092/auth-client 1.0.0 → 1.0.2

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 (3) hide show
  1. package/Readme.md +1 -1
  2. package/core.js +16 -6
  3. package/package.json +5 -5
package/Readme.md CHANGED
@@ -7,7 +7,7 @@ A lightweight, framework-agnostic authentication client SDK designed for scalabl
7
7
  ## 📦 Installation
8
8
 
9
9
  ```bash
10
- npm install auth-client
10
+ npm install @spidy092/auth-client
11
11
  ```
12
12
 
13
13
  ---
package/core.js CHANGED
@@ -3,10 +3,10 @@ import { setToken, clearToken, getToken } from './token';
3
3
  import { getConfig } from './config';
4
4
 
5
5
  export function login(clientKeyArg, redirectUriArg, stateArg) {
6
- const {
6
+ const {
7
7
  clientKey: defaultClientKey,
8
8
  authBaseUrl,
9
- redirectUri: defaultRedirectUri,
9
+ redirectUri: defaultRedirectUri,
10
10
  accountUiUrl
11
11
  } = getConfig();
12
12
 
@@ -18,22 +18,32 @@ export function login(clientKeyArg, redirectUriArg, stateArg) {
18
18
  throw new Error('Missing clientKey or redirectUri');
19
19
  }
20
20
 
21
- // Store original app info for return after auth
21
+ // Store state for callback validation
22
22
  sessionStorage.setItem('authState', state);
23
23
  sessionStorage.setItem('originalApp', clientKey);
24
24
  sessionStorage.setItem('returnUrl', redirectUri);
25
25
 
26
- // Redirect to centralized Account UI instead of direct auth service
26
+ // --- ENTERPRISE LOGIC ---
27
+ // If we are already in Account-UI, go straight to the backend
28
+ if (window.location.origin === accountUiUrl && clientKey === 'account-ui') {
29
+ // Direct SSO kick-off for Account-UI
30
+ const backendLoginUrl = `${authBaseUrl}/login/${clientKey}?redirect_uri=${encodeURIComponent(redirectUri)}&state=${encodeURIComponent(state)}`;
31
+ console.log('Redirecting directly to auth backend:', backendLoginUrl);
32
+ window.location.href = backendLoginUrl;
33
+ return;
34
+ }
35
+
36
+ // Otherwise, centralized login flow (for other apps)
27
37
  const accountLoginUrl = `${accountUiUrl}/login?` + new URLSearchParams({
28
38
  client: clientKey,
29
39
  redirect_uri: redirectUri,
30
40
  state: state
31
41
  });
32
-
33
- console.log('Redirecting to Account UI:', accountLoginUrl);
42
+ console.log('Redirecting to centralized Account UI:', accountLoginUrl);
34
43
  window.location.href = accountLoginUrl;
35
44
  }
36
45
 
46
+
37
47
  export function logout() {
38
48
  const { clientKey, authBaseUrl, accountUiUrl } = getConfig();
39
49
  const token = getToken();
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
- "name": "@spidy092/auth-client",
3
- "version": "1.0.0",
2
+ "name": "@spidy092/auth-client",
3
+ "version": "1.0.2",
4
4
  "description": "Scalable frontend auth SDK for centralized login using Keycloak + Auth Service.",
5
- "main": "index.js",
6
- "module": "index.js",
7
- "type": "module",
5
+ "main": "index.js",
6
+ "module": "index.js",
7
+ "type": "module",
8
8
  "exports": {
9
9
  ".": "./index.js",
10
10
  "./react/AuthProvider": "./react/AuthProvider.jsx",