hoodiehq / hoodie-account-client

:dog: Account client API for the browser
https://hoodiehq.github.io/hoodie-account-client
Apache License 2.0
11 stars 24 forks source link

Signing out and in uses wrong store URL #116

Closed MattCed closed 8 years ago

MattCed commented 8 years ago

I have an application with several users on the same device, using couchDB as database. When i signOut from one account and then signIn with another, hoodie tries to use a URL associated with the first account to fetch data, thus resulting in an authentication error. I have isolated the problem by writing some console commands as follows: (I tried the same with a new application using only Pouch and then the error does not occur)

-hoodie.account.signUp({username:"qqq", password:"qqq"}).then(function(data){console.log(data);},function(err){console.log(err)}) Promise {state: Array[1], queue: Array[0], outcome: undefined} VM140:1 Object {id: "anew2o3", username: "qqq"} -hoodie.account.signIn({username:"qqq", password:"qqq"}).then(function(data){console.log(data);},function(err){console.log(err)}) Promise {state: Array[1], queue: Array[0], outcome: undefined} VM188:1 Object {id: "anew2o3", username: "qqq", roles: Array[0]} client.js:21135 GET http://192.168.1.11:8080/hoodie/store/api/user%2Fanew2o3/_local/XfLbJu8f3JF_GBAMqcOa5g%3D%3D? 404 (Not Found)xhRequest @ client.js:21135ajax$1 @ client.js:21154ajaxCore @ client.js:21248ajax @ client.js:21305ajax$$ @ client.js:21454(anonymous function) @ client.js:21459ajaxPromise @ client.js:21458(anonymous function) @ client.js:21755(anonymous function) @ client.js:21471 client.js:21135 GET http://192.168.1.11:8080/hoodie/store/api/user%2Fanew2o3/_local/XfLbJu8f3JF_GBAMqcOa5g%3D%3D? 404 (Not Found)xhRequest @ client.js:21135ajax$1 @ client.js:21154ajaxCore @ client.js:21248ajax @ client.js:21305ajax$$ @ client.js:21454(anonymous function) @ client.js:21459ajaxPromise @ client.js:21458(anonymous function) @ client.js:21755(anonymous function) @ client.js:21471 client.js:14404 The above 404 is totally normal. PouchDB is just checking if a remote checkpoint exists. client.js:21135 GET http://192.168.1.11:8080/hoodie/store/api/user%2Fanew2o3/_local/b20gmrOr9qMxlHv7bFTl5w%3D%3D? 404 (Not Found)xhRequest @ client.js:21135ajax$1 @ client.js:21154ajaxCore @ client.js:21248ajax @ client.js:21305ajax$$ @ client.js:21454(anonymous function) @ client.js:21459ajaxPromise @ client.js:21458(anonymous function) @ client.js:21755(anonymous function) @ client.js:21471 client.js:14404 The above 404 is totally normal. PouchDB is just checking if a remote checkpoint exists. -hoodie.account.signOut().then(function(data){console.log(data);},function(err){console.log(err)}) Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined} VM232:1 Object {username: "qqq", session: Object, id: "anew2o3"} -hoodie.account.signUp({username:"www", password:"www"}).then(function(data){console.log(data);},function(err){console.log(err)}) Promise {state: Array[1], queue: Array[0], outcome: undefined} VM235:1 Object {id: "3hpzafc", username: "www"} -hoodie.account.signIn({username:"www", password:"www"}).then(function(data){console.log(data);},function(err){console.log(err)}) Promise {state: Array[1], queue: Array[0], outcome: undefined} VM236:1 Object {id: "3hpzafc", username: "www", roles: Array[0]} client.js:21135 GET http://192.168.1.11:8080/hoodie/store/api**/user%2Fanew2o3**/ 401 (Unauthorized)

xhRequest @ client.js:21135ajax$1 @ client.js:21154ajaxCore @ client.js:21248ajax @ client.js:21305ajax$$ @ client.js:21454(anonymous function) @ client.js:21459ajaxPromise @ client.js:21458setup @ client.js:21495(anonymous function) @ client.js:21470(anonymous function) @ client.js:2467(anonymous function) @ client.js:14132(anonymous function) @ client.js:2467(anonymous function) @ client.js:14069(anonymous function) @ client.js:14056(anonymous function) @ client.js:2467(anonymous function) @ client.js:14127TaskQueue.execute @ client.js:16541TaskQueue.ready @ client.js:16554(anonymous function) @ client.js:16724(anonymous function) @ client.js:21521 client.js:21135 GET http://192.168.1.11:8080/hoodie/store/api/user%2Fanew2o3/ 401 (Unauthorized)xhRequest @ client.js:21135ajax$1 @ client.js:21154ajaxCore @ client.js:21248ajax @ client.js:21305ajax$$ @ client.js:21454(anonymous function) @ client.js:21459ajaxPromise @ client.js:21458setup @ client.js:21495(anonymous function) @ client.js:21470(anonymous function) @ client.js:2467(anonymous function) @ client.js:14132(anonymous function) @ client.js:2467(anonymous function) @ client.js:14069(anonymous function) @ client.js:14056(anonymous function) @ client.js:2469generateReplicationId @ client.js:23853initCheckpointer @ client.js:23908startChanges @ client.js:24234replicate$1 @ client.js:24303(anonymous function) @ client.js:24120

MattCed commented 8 years ago

Workaround. If I reload the page with location.reload() after signing in with a new user hoodie start to use the correct URL, but it is not a very elegant solution.

gr2m commented 8 years ago

@MattCed the problem here is not that you sign out and back into the same account, but you sign out, signup for a new account, sign in to the new account, and it wrongly tries connects to the database of the first user, right?

MattCed commented 8 years ago

Yes, That is correct. And after that the wrong backend URL is used every time I switch account. When that happens it is not possible to signOut anymore. If I restart the app I am automatically logged in again though and it works fine until I switch account again.

gr2m commented 8 years ago

Thanks a lot, I’ll have a look into it!

gr2m commented 8 years ago

This issue was resolved via https://github.com/hoodiehq/hoodie-store-client/releases/tag/v5.0.3. Can you update to the latest hoodie? Version 23.3.0 or above should work, the latest is v23.3.3. If the error still persists, try to rm .hoodie/client.js to delete the cached hoodie client, but it should do that automatically if it detects updated dependencies

MattCed commented 8 years ago

Thanks a lot. I actually used 23.3.3, or rather I thought i did, but when I went into reset.js I noticed that the reset() function was the old one. What happened was that I changed the name of my main project directory in June, but some of the package.json files in node_modules/@hoodie... contained absolute paths so the files were not updated in the correct place. So according to npm I was using 23.3.3, but I really was not. (Note to self: Don't change directory names :-) )

gr2m commented 8 years ago

Glad we figured it out :)