@nauth-toolkit/client 0.1.84 → 0.1.86
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/index.cjs +14 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +14 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1538,13 +1538,19 @@ var NAuthClient = class {
|
|
|
1538
1538
|
}
|
|
1539
1539
|
/**
|
|
1540
1540
|
* Build request headers for authentication.
|
|
1541
|
+
*
|
|
1542
|
+
* @param auth - Whether to include authentication headers
|
|
1543
|
+
* @param method - HTTP method (GET, POST, PUT, DELETE, PATCH)
|
|
1544
|
+
* @returns Headers object with auth, CSRF, and device trust headers
|
|
1541
1545
|
* @private
|
|
1542
1546
|
*/
|
|
1543
|
-
async buildHeaders(auth) {
|
|
1547
|
+
async buildHeaders(auth, method = "GET") {
|
|
1544
1548
|
const headers = {
|
|
1545
|
-
"Content-Type": "application/json",
|
|
1546
1549
|
...this.config.headers
|
|
1547
1550
|
};
|
|
1551
|
+
if (method !== "GET") {
|
|
1552
|
+
headers["Content-Type"] = "application/json";
|
|
1553
|
+
}
|
|
1548
1554
|
if (auth && this.config.tokenDelivery === "json") {
|
|
1549
1555
|
const accessToken = (await this.tokenManager.getTokens()).accessToken;
|
|
1550
1556
|
if (accessToken) {
|
|
@@ -1560,7 +1566,8 @@ var NAuthClient = class {
|
|
|
1560
1566
|
} catch {
|
|
1561
1567
|
}
|
|
1562
1568
|
}
|
|
1563
|
-
|
|
1569
|
+
const mutatingMethods = ["POST", "PUT", "PATCH", "DELETE"];
|
|
1570
|
+
if (this.config.tokenDelivery === "cookies" && hasWindow() && mutatingMethods.includes(method)) {
|
|
1564
1571
|
const csrfToken = this.getCsrfToken();
|
|
1565
1572
|
if (csrfToken) {
|
|
1566
1573
|
headers[this.config.csrf.headerName] = csrfToken;
|
|
@@ -1583,7 +1590,7 @@ var NAuthClient = class {
|
|
|
1583
1590
|
*/
|
|
1584
1591
|
async get(path, auth = false) {
|
|
1585
1592
|
const url = this.buildUrl(path);
|
|
1586
|
-
const headers = await this.buildHeaders(auth);
|
|
1593
|
+
const headers = await this.buildHeaders(auth, "GET");
|
|
1587
1594
|
const credentials = this.config.tokenDelivery === "cookies" ? "include" : "omit";
|
|
1588
1595
|
const response = await this.config.httpAdapter.request({
|
|
1589
1596
|
method: "GET",
|
|
@@ -1599,7 +1606,7 @@ var NAuthClient = class {
|
|
|
1599
1606
|
*/
|
|
1600
1607
|
async post(path, body, auth = false) {
|
|
1601
1608
|
const url = this.buildUrl(path);
|
|
1602
|
-
const headers = await this.buildHeaders(auth);
|
|
1609
|
+
const headers = await this.buildHeaders(auth, "POST");
|
|
1603
1610
|
const credentials = this.config.tokenDelivery === "cookies" ? "include" : "omit";
|
|
1604
1611
|
const response = await this.config.httpAdapter.request({
|
|
1605
1612
|
method: "POST",
|
|
@@ -1616,7 +1623,7 @@ var NAuthClient = class {
|
|
|
1616
1623
|
*/
|
|
1617
1624
|
async put(path, body, auth = false) {
|
|
1618
1625
|
const url = this.buildUrl(path);
|
|
1619
|
-
const headers = await this.buildHeaders(auth);
|
|
1626
|
+
const headers = await this.buildHeaders(auth, "PUT");
|
|
1620
1627
|
const credentials = this.config.tokenDelivery === "cookies" ? "include" : "omit";
|
|
1621
1628
|
const response = await this.config.httpAdapter.request({
|
|
1622
1629
|
method: "PUT",
|
|
@@ -1633,7 +1640,7 @@ var NAuthClient = class {
|
|
|
1633
1640
|
*/
|
|
1634
1641
|
async delete(path, auth = false) {
|
|
1635
1642
|
const url = this.buildUrl(path);
|
|
1636
|
-
const headers = await this.buildHeaders(auth);
|
|
1643
|
+
const headers = await this.buildHeaders(auth, "DELETE");
|
|
1637
1644
|
const credentials = this.config.tokenDelivery === "cookies" ? "include" : "omit";
|
|
1638
1645
|
const response = await this.config.httpAdapter.request({
|
|
1639
1646
|
method: "DELETE",
|