This is probably a problem with the server. Make sure your user session is being cleared when you login with new credentials.
Confused by AFNetworking responseObject
-
23-06-2023 - |
سؤال
It's probably me. I'm probably doing something dumb. I'm baffled by the responseObject so have put together the simplest possible demonstration I can think of.
I want to use AFNetworking 2 in an iOS App to log in to a remote server to get an authToken. I thought everything was working fine. I can log in and get an AuthToken.
However..... if I log out and then log in as a different user I appear to get the first users responseObject and not a new one.
I have recorded a short video demonstrating the issue. This shows the iOS simulator, xCode debugger and web server log files all side-by-side. You can view it here: https://www.dropbox.com/s/f0zjdsj2mor0cjq/wrongresponsobject.mp4
Steps to reproduce:
- Log in as user1 using the demo app with the details below
- Log in again as user2 with the details below
Each time a log in is attempted I can see the request in the server logs. The correct request, with the correct email and password is being posted. The server is returning a 201 response with some response data including an authToken.
When processing the *response on the second login, the original responseObject is used and not a new one to match the new request.
I have a working demo server: domain: apitest.jserve1.com/ path-to-sign-in: /api/v1/session.json
test user accounts
user1@example.com / user1password
user2@example.com / user2password
I have a demo app which connects to this demo server that you can download here https://www.dropbox.com/s/zp62sjlb13z3g6q/WrongObjectResponseExample.zip
Am I missing something obvious? Being dumb? If so then I'd really appreciate it if you could tell me what I'm doing wrong.
UPDATE - SOLVED
The issue was that the app was retaining cookies from the previous login. In the end, adding the following code fixed the issue for me.
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL: networkServerAddress];
for (NSHTTPCookie *cookie in cookies) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
via stackoverflow.com/questions/10984374/how-to-manage-sessions-with-afnetworking
المحلول