-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter Web read cookies #745
Comments
I ended up using |
hi. can you please share your code how? we probably ended up here and used the same strategy with regards to csrf and jwt token. i got it to work in android but res.headers returns no set-cookie in flutter web. my problem is that there is no set-cookie when the response.headers is even printed out after login. but in android and in postman, there is a set-cookie there. |
can you please share the code snippet for that? I tried to read like following but the response was empty. Able to see the set-cookie value in my chrome network tab.
|
In case someone else is searching for a solution: Using import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:universal_html/html.dart' show document;
String? readWebCookie(String name) {
if (!kIsWeb) {
return null;
}
String cookies = document.cookie ?? "";
for (String value in cookies.isNotEmpty ? cookies.split(";") : []) {
List<String> map = value.split("=");
String key = map[0].trim();
if (name == key) {
return map[1].trim();
}
}
return null;
} |
I'm wanting to read a cookie. A system I'm working with requires me to read a cookie value and return it as a HTTP header to prevent CSRF. It appears there is currently no way to get the cookie value from the response when using the web platform.
The text was updated successfully, but these errors were encountered: