better-auth 0.3.5 → 0.3.6

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/api.js CHANGED
@@ -1365,6 +1365,26 @@ var callbackOAuth = createAuthEndpoint(
1365
1365
  `${c.context.baseURL}/error?error=oauth_provider_not_found`
1366
1366
  );
1367
1367
  }
1368
+ const parsedState = parseState(c.query.state);
1369
+ if (!parsedState.success) {
1370
+ c.context.logger.error("Unable to parse state");
1371
+ throw c.redirect(
1372
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1373
+ );
1374
+ }
1375
+ const {
1376
+ data: { callbackURL, currentURL, dontRememberMe, code }
1377
+ } = parsedState;
1378
+ const storedCode = await c.getSignedCookie(
1379
+ c.context.authCookies.state.name,
1380
+ c.context.secret
1381
+ );
1382
+ if (storedCode !== code) {
1383
+ logger.error("Oauth code mismatch", storedCode, code);
1384
+ throw c.redirect(
1385
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1386
+ );
1387
+ }
1368
1388
  const codeVerifier = await c.getSignedCookie(
1369
1389
  c.context.authCookies.pkCodeVerifier.name,
1370
1390
  c.context.secret
@@ -1379,7 +1399,7 @@ var callbackOAuth = createAuthEndpoint(
1379
1399
  } catch (e) {
1380
1400
  c.context.logger.error(e);
1381
1401
  throw c.redirect(
1382
- `${c.context.baseURL}/error?error=oauth_code_verification_failed`
1402
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1383
1403
  );
1384
1404
  }
1385
1405
  const user = await provider.getUserInfo(tokens).then((res) => res?.user);
@@ -1388,23 +1408,15 @@ var callbackOAuth = createAuthEndpoint(
1388
1408
  ...user,
1389
1409
  id
1390
1410
  });
1391
- const parsedState = parseState(c.query.state);
1392
- if (!parsedState.success) {
1393
- c.context.logger.error("Unable to parse state");
1394
- throw c.redirect(
1395
- `${c.context.baseURL}/error?error=invalid_state_parameter`
1396
- );
1397
- }
1398
- const { callbackURL, currentURL, dontRememberMe } = parsedState.data;
1399
1411
  if (!user || data.success === false) {
1400
1412
  logger.error("Unable to get user info", data.error);
1401
1413
  throw c.redirect(
1402
- `${c.context.baseURL}/error?error=oauth_validation_failed`
1414
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1403
1415
  );
1404
1416
  }
1405
1417
  if (!callbackURL) {
1406
1418
  throw c.redirect(
1407
- `${c.context.baseURL}/error?error=oauth_callback_url_not_found`
1419
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1408
1420
  );
1409
1421
  }
1410
1422
  const dbUser = await c.context.internalAdapter.findUserByEmail(user.email).catch((e) => {
@@ -1491,7 +1503,7 @@ var callbackOAuth = createAuthEndpoint(
1491
1503
  throw c.redirect(url.toString());
1492
1504
  }
1493
1505
  } catch {
1494
- const url = new URL(currentURL || callbackURL);
1506
+ const url = new URL(currentURL || callbackURL || "");
1495
1507
  url.searchParams.set("error", "unable_to_create_session");
1496
1508
  throw c.redirect(url.toString());
1497
1509
  }
package/dist/index.js CHANGED
@@ -1474,6 +1474,26 @@ var callbackOAuth = createAuthEndpoint(
1474
1474
  `${c.context.baseURL}/error?error=oauth_provider_not_found`
1475
1475
  );
1476
1476
  }
1477
+ const parsedState = parseState(c.query.state);
1478
+ if (!parsedState.success) {
1479
+ c.context.logger.error("Unable to parse state");
1480
+ throw c.redirect(
1481
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1482
+ );
1483
+ }
1484
+ const {
1485
+ data: { callbackURL, currentURL, dontRememberMe, code }
1486
+ } = parsedState;
1487
+ const storedCode = await c.getSignedCookie(
1488
+ c.context.authCookies.state.name,
1489
+ c.context.secret
1490
+ );
1491
+ if (storedCode !== code) {
1492
+ logger.error("Oauth code mismatch", storedCode, code);
1493
+ throw c.redirect(
1494
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1495
+ );
1496
+ }
1477
1497
  const codeVerifier = await c.getSignedCookie(
1478
1498
  c.context.authCookies.pkCodeVerifier.name,
1479
1499
  c.context.secret
@@ -1488,7 +1508,7 @@ var callbackOAuth = createAuthEndpoint(
1488
1508
  } catch (e) {
1489
1509
  c.context.logger.error(e);
1490
1510
  throw c.redirect(
1491
- `${c.context.baseURL}/error?error=oauth_code_verification_failed`
1511
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1492
1512
  );
1493
1513
  }
1494
1514
  const user = await provider.getUserInfo(tokens).then((res) => res?.user);
@@ -1497,23 +1517,15 @@ var callbackOAuth = createAuthEndpoint(
1497
1517
  ...user,
1498
1518
  id
1499
1519
  });
1500
- const parsedState = parseState(c.query.state);
1501
- if (!parsedState.success) {
1502
- c.context.logger.error("Unable to parse state");
1503
- throw c.redirect(
1504
- `${c.context.baseURL}/error?error=invalid_state_parameter`
1505
- );
1506
- }
1507
- const { callbackURL, currentURL, dontRememberMe } = parsedState.data;
1508
1520
  if (!user || data.success === false) {
1509
1521
  logger.error("Unable to get user info", data.error);
1510
1522
  throw c.redirect(
1511
- `${c.context.baseURL}/error?error=oauth_validation_failed`
1523
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1512
1524
  );
1513
1525
  }
1514
1526
  if (!callbackURL) {
1515
1527
  throw c.redirect(
1516
- `${c.context.baseURL}/error?error=oauth_callback_url_not_found`
1528
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1517
1529
  );
1518
1530
  }
1519
1531
  const dbUser = await c.context.internalAdapter.findUserByEmail(user.email).catch((e) => {
@@ -1600,7 +1612,7 @@ var callbackOAuth = createAuthEndpoint(
1600
1612
  throw c.redirect(url.toString());
1601
1613
  }
1602
1614
  } catch {
1603
- const url = new URL(currentURL || callbackURL);
1615
+ const url = new URL(currentURL || callbackURL || "");
1604
1616
  url.searchParams.set("error", "unable_to_create_session");
1605
1617
  throw c.redirect(url.toString());
1606
1618
  }
package/dist/plugins.js CHANGED
@@ -1286,6 +1286,26 @@ var callbackOAuth = createAuthEndpoint(
1286
1286
  `${c.context.baseURL}/error?error=oauth_provider_not_found`
1287
1287
  );
1288
1288
  }
1289
+ const parsedState = parseState(c.query.state);
1290
+ if (!parsedState.success) {
1291
+ c.context.logger.error("Unable to parse state");
1292
+ throw c.redirect(
1293
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1294
+ );
1295
+ }
1296
+ const {
1297
+ data: { callbackURL, currentURL, dontRememberMe, code }
1298
+ } = parsedState;
1299
+ const storedCode = await c.getSignedCookie(
1300
+ c.context.authCookies.state.name,
1301
+ c.context.secret
1302
+ );
1303
+ if (storedCode !== code) {
1304
+ logger.error("Oauth code mismatch", storedCode, code);
1305
+ throw c.redirect(
1306
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1307
+ );
1308
+ }
1289
1309
  const codeVerifier = await c.getSignedCookie(
1290
1310
  c.context.authCookies.pkCodeVerifier.name,
1291
1311
  c.context.secret
@@ -1300,7 +1320,7 @@ var callbackOAuth = createAuthEndpoint(
1300
1320
  } catch (e) {
1301
1321
  c.context.logger.error(e);
1302
1322
  throw c.redirect(
1303
- `${c.context.baseURL}/error?error=oauth_code_verification_failed`
1323
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1304
1324
  );
1305
1325
  }
1306
1326
  const user = await provider.getUserInfo(tokens).then((res) => res?.user);
@@ -1309,23 +1329,15 @@ var callbackOAuth = createAuthEndpoint(
1309
1329
  ...user,
1310
1330
  id
1311
1331
  });
1312
- const parsedState = parseState(c.query.state);
1313
- if (!parsedState.success) {
1314
- c.context.logger.error("Unable to parse state");
1315
- throw c.redirect(
1316
- `${c.context.baseURL}/error?error=invalid_state_parameter`
1317
- );
1318
- }
1319
- const { callbackURL, currentURL, dontRememberMe } = parsedState.data;
1320
1332
  if (!user || data.success === false) {
1321
1333
  logger.error("Unable to get user info", data.error);
1322
1334
  throw c.redirect(
1323
- `${c.context.baseURL}/error?error=oauth_validation_failed`
1335
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1324
1336
  );
1325
1337
  }
1326
1338
  if (!callbackURL) {
1327
1339
  throw c.redirect(
1328
- `${c.context.baseURL}/error?error=oauth_callback_url_not_found`
1340
+ `${c.context.baseURL}/error?error=please_restart_the_process`
1329
1341
  );
1330
1342
  }
1331
1343
  const dbUser = await c.context.internalAdapter.findUserByEmail(user.email).catch((e) => {
@@ -1412,7 +1424,7 @@ var callbackOAuth = createAuthEndpoint(
1412
1424
  throw c.redirect(url.toString());
1413
1425
  }
1414
1426
  } catch {
1415
- const url = new URL(currentURL || callbackURL);
1427
+ const url = new URL(currentURL || callbackURL || "");
1416
1428
  url.searchParams.set("error", "unable_to_create_session");
1417
1429
  throw c.redirect(url.toString());
1418
1430
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "The most comprehensive authentication library for TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",