@korajs/auth 1.0.0-beta.0 → 1.0.0-beta.1

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.
package/dist/server.cjs CHANGED
@@ -405,7 +405,7 @@ var MAX_PASSWORD_LENGTH = 128;
405
405
  var MAX_NAME_LENGTH = 200;
406
406
  var CHALLENGE_TTL_MS = 6e4;
407
407
  function isValidEmail(email) {
408
- if (email.length === 0 || email.length > 254) {
408
+ if (typeof email !== "string" || email.length === 0 || email.length > 254) {
409
409
  return false;
410
410
  }
411
411
  const atIndex = email.indexOf("@");
@@ -425,6 +425,9 @@ function isValidEmail(email) {
425
425
  return true;
426
426
  }
427
427
  function sanitizeName(name) {
428
+ if (typeof name !== "string") {
429
+ return "";
430
+ }
428
431
  const cleaned = name.replace(/[\x00-\x1f\x7f]/g, "");
429
432
  const trimmed = cleaned.trim();
430
433
  if (trimmed.length > MAX_NAME_LENGTH) {
@@ -475,7 +478,7 @@ var BuiltInAuthRoutes = class {
475
478
  }
476
479
  };
477
480
  }
478
- if (body.password.length < MIN_PASSWORD_LENGTH) {
481
+ if (typeof body.password !== "string" || body.password.length < MIN_PASSWORD_LENGTH) {
479
482
  return {
480
483
  status: 400,
481
484
  body: {
@@ -539,6 +542,12 @@ var BuiltInAuthRoutes = class {
539
542
  * @returns Auth response with the user and tokens, or an error
540
543
  */
541
544
  async handleSignIn(body, clientIp) {
545
+ if (typeof body.email !== "string" || typeof body.password !== "string") {
546
+ return {
547
+ status: 400,
548
+ body: { error: "Email and password are required." }
549
+ };
550
+ }
542
551
  const rateLimitKey = clientIp ? `signin:${body.email.toLowerCase()}:${clientIp}` : `signin:${body.email.toLowerCase()}`;
543
552
  if (!await this.rateLimiter.isAllowed(rateLimitKey)) {
544
553
  return {
@@ -1046,6 +1055,9 @@ function decodeJwt(token) {
1046
1055
  }
1047
1056
  }
1048
1057
  function verifyJwt(token, secret) {
1058
+ if (typeof token !== "string") {
1059
+ return null;
1060
+ }
1049
1061
  const parts = token.split(".");
1050
1062
  if (parts.length !== 3) {
1051
1063
  return null;
@@ -2057,6 +2069,11 @@ function createDefaultTokenManager(options) {
2057
2069
  "createKoraAuthServer requires jwtSecret in production. Set KORA_AUTH_SECRET or pass jwtSecret."
2058
2070
  );
2059
2071
  }
2072
+ if (!secret) {
2073
+ console.warn(
2074
+ "[kora] No JWT secret configured; using an ephemeral random secret. Every token is invalidated when the process restarts. Set KORA_AUTH_SECRET or pass jwtSecret to createKoraAuthServer for stable sessions."
2075
+ );
2076
+ }
2060
2077
  return new TokenManager({
2061
2078
  secret: secret ?? TokenManager.generateSecret(),
2062
2079
  revocationStore: new InMemoryTokenRevocationStore(),
@@ -2359,7 +2376,11 @@ function notFound() {
2359
2376
  return { status: 404, body: { error: "Not found" } };
2360
2377
  }
2361
2378
  function readEnvSecret() {
2362
- return typeof process !== "undefined" ? process.env.KORA_AUTH_SECRET : void 0;
2379
+ if (typeof process === "undefined") {
2380
+ return void 0;
2381
+ }
2382
+ const value = process.env.KORA_AUTH_SECRET;
2383
+ return value && value.trim().length > 0 ? value : void 0;
2363
2384
  }
2364
2385
  function isProduction() {
2365
2386
  return typeof process !== "undefined" && process.env.NODE_ENV === "production";
@@ -4222,7 +4243,7 @@ var MAX_ORG_NAME_LENGTH = 200;
4222
4243
  var MAX_SLUG_LENGTH = 100;
4223
4244
  var SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{0,98}[a-z0-9]$/;
4224
4245
  function isValidEmail2(email) {
4225
- if (email.length === 0 || email.length > 254) return false;
4246
+ if (typeof email !== "string" || email.length === 0 || email.length > 254) return false;
4226
4247
  const atIndex = email.indexOf("@");
4227
4248
  if (atIndex < 1) return false;
4228
4249
  const domain = email.slice(atIndex + 1);