getPersonalizedURL not compatible with NextJS v13
- Dominant language
- TypeScript
- Stars
- 8.8k
- Forks
- 1.2k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 17
Description
**Describe the bug**
When running NextJS v13, `getPersonalizedURL` causes a `request.cookies.entries is not a function` error.
`getPersonalizedURL` relies on the `NextRequest`, which has changed in NextJS 13. Cookies now have a `name` and a `value` prop, and there is no longer `request.cookies.entries`.
**To Reproduce**
Steps to reproduce the behavior:
1. On an application running NextJS v13, run middleware using `getPersonalizedURL` following instruction in the documentation.
**Expected behavior**
A personalized URL should be generated.
**Additional context**
Replacing
```
const allCookies = Array.from(request.cookies.entries()).reduce(
(acc, [key]) => ({
...acc,
[key]: tryJsonParse(request.cookies.get(key)!),
}),
{}
);
```
with
```
const allCookies: Record = {};
for (const cookie of request.cookies) {
const key = cookie[0];
const value = request.cookies.get(key)?.value;
if (value) {
const parsedCookie = tryJsonParse(value);
allCookies[key] = parsedCookie;
}
}
```
appears to solve the issue for us.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.