@~lyre/auth 0.0.5 → 0.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.
@@ -2,11 +2,15 @@
2
2
  import { createHmac, timingSafeEqual } from "crypto";
3
3
  var SESSION_COOKIE_NAME = "platform_session";
4
4
  var STATE_COOKIE_NAME = "accounts_auth_state";
5
+ function normalizeOptionalString(value) {
6
+ const trimmed = value?.trim();
7
+ return trimmed ? trimmed : void 0;
8
+ }
5
9
  function createAccountsClientConfig(input = {}) {
6
10
  return {
7
- baseUrl: input.baseUrl ?? process.env.ACCOUNTS_BASE_URL,
11
+ baseUrl: normalizeOptionalString(input.baseUrl ?? process.env.ACCOUNTS_BASE_URL),
8
12
  clientId: input.clientId ?? process.env.ACCOUNTS_CLIENT_ID ?? "accounts-app",
9
- clientSecret: input.clientSecret ?? process.env.ACCOUNTS_CLIENT_SECRET,
13
+ clientSecret: normalizeOptionalString(input.clientSecret ?? process.env.ACCOUNTS_CLIENT_SECRET),
10
14
  redirectUri: input.redirectUri ?? process.env.ACCOUNTS_REDIRECT_URI ?? "http://localhost:5173/auth/callback",
11
15
  logoutRedirectUri: input.logoutRedirectUri ?? process.env.ACCOUNTS_LOGOUT_REDIRECT_URI ?? "http://localhost:5173/",
12
16
  useMock: input.useMock ?? (process.env.ACCOUNTS_USE_MOCK === "true" || !process.env.ACCOUNTS_BASE_URL || !process.env.ACCOUNTS_CLIENT_ID)
@@ -94,18 +98,22 @@ async function exchangeAuthorizationCode(input) {
94
98
  return createMockTokenResponse(input.code);
95
99
  }
96
100
  const fetchImpl = input.fetchImpl ?? fetch;
101
+ const clientSecret = normalizeOptionalString(input.config.clientSecret);
102
+ const tokenBody = {
103
+ grant_type: "authorization_code",
104
+ code: input.code,
105
+ redirect_uri: input.config.redirectUri,
106
+ client_id: input.config.clientId
107
+ };
108
+ if (clientSecret) {
109
+ tokenBody.client_secret = clientSecret;
110
+ }
97
111
  const response = await fetchImpl(new URL("/api/auth/token", input.config.baseUrl), {
98
112
  method: "POST",
99
113
  headers: {
100
114
  "content-type": "application/json"
101
115
  },
102
- body: JSON.stringify({
103
- grant_type: "authorization_code",
104
- code: input.code,
105
- redirect_uri: input.config.redirectUri,
106
- client_id: input.config.clientId,
107
- client_secret: input.config.clientSecret
108
- })
116
+ body: JSON.stringify(tokenBody)
109
117
  });
110
118
  if (!response.ok) {
111
119
  throw new Error(`Accounts token exchange failed with status ${response.status}.`);
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  readPlatformSessionCookie,
10
10
  resolveActiveTenant,
11
11
  syncAccountsUser
12
- } from "./chunk-LMIRQKLN.js";
12
+ } from "./chunk-RADVGFYQ.js";
13
13
  export {
14
14
  beginAccountsLoginRedirect,
15
15
  clearPlatformSessionCookie,
package/dist/sveltekit.js CHANGED
@@ -4,10 +4,9 @@ import {
4
4
  handleAccountsCallback,
5
5
  identityPassthroughSync,
6
6
  readPlatformSessionCookie
7
- } from "./chunk-LMIRQKLN.js";
7
+ } from "./chunk-RADVGFYQ.js";
8
8
 
9
9
  // src/sveltekit.ts
10
- import { redirect } from "@sveltejs/kit";
11
10
  var STATE_COOKIE = "accounts_auth_state";
12
11
  function redirectWithCookies(location, cookies) {
13
12
  const headers = new Headers({ location });
@@ -65,7 +64,7 @@ function createAuthHandle(opts) {
65
64
  headers: { "content-type": "application/json" }
66
65
  });
67
66
  }
68
- throw redirect(302, `${loginPath}?next=${encodeURIComponent(path + event.url.search)}`);
67
+ return redirectWithCookies(`${loginPath}?next=${encodeURIComponent(path + event.url.search)}`, []);
69
68
  }
70
69
  return resolve(event);
71
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@~lyre/auth",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Shared Axis Accounts auth SDK — framework-agnostic session/identity core (HMAC-signed cookies, accounts login/callback/logout) plus an optional turnkey SvelteKit adapter.",
5
5
  "type": "module",
6
6
  "sideEffects": false,