You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: clarify how to expire cookies with Path/Domain
Remove ExpireCookie method - the existing Cookie() method handles this
use case by setting Expires to fasthttp.CookieExpireDelete.
Updated documentation to show the recommended approach.
Fixes#2878
Alternatively, use `ExpireCookie` for a cleaner approach (see below).
1774
-
1775
-
### ExpireCookie
1776
-
1777
-
Expires a cookie by its cookie definition. This is useful when you need to expire a cookie that was set with a specific `Path` or `Domain`. The browser will only clear the cookie if the `Path` and `Domain` attributes match the original cookie.
You can also use `c.Cookie()` to expire cookies with specific `Path` or `Domain` attributes:
1782
1773
1783
1774
```go title="Example"
1784
1775
app.Get("/logout", func(c fiber.Ctx) error {
1785
-
// Expire a cookie with specific path
1786
-
c.Res().ExpireCookie(&fiber.Cookie{
1787
-
Name: "session",
1788
-
Path: "/admin",
1789
-
})
1790
-
1791
-
// Expire a cookie with specific domain
1792
-
c.Res().ExpireCookie(&fiber.Cookie{
1793
-
Name: "auth",
1794
-
Domain: "example.com",
1795
-
})
1796
-
1797
-
// Expire a cookie with path, domain, and security flags
1798
-
c.Res().ExpireCookie(&fiber.Cookie{
1799
-
Name: "token",
1800
-
Path: "/api",
1801
-
Domain: "example.com",
1802
-
Secure: true,
1803
-
HTTPOnly: true,
1804
-
})
1805
-
1806
-
// Expire a cookie with SameSite attribute
1807
-
c.Res().ExpireCookie(&fiber.Cookie{
1808
-
Name: "csrf",
1809
-
SameSite: "Strict",
1810
-
})
1811
-
1812
-
// Expire a partitioned cookie (CHIPS)
1813
-
c.Res().ExpireCookie(&fiber.Cookie{
1814
-
Name: "embedded",
1815
-
Partitioned: true,
1776
+
// Expire a cookie with path and domain
1777
+
c.Cookie(&fiber.Cookie{
1778
+
Name: "token",
1779
+
Path: "/api",
1780
+
Domain: "example.com",
1781
+
Expires: fasthttp.CookieExpireDelete,
1816
1782
})
1817
1783
1818
1784
return c.SendStatus(fiber.StatusOK)
1819
1785
})
1820
1786
```
1821
1787
1822
-
:::note
1823
-
Only the `Name`, `Path`, `Domain`, `Secure`, `HTTPOnly`, `SameSite`, and `Partitioned` fields are used from the Cookie struct. The `Value` and `Expires` fields are overwritten to expire the cookie.
0 commit comments