Comments (8)
Hmm, try setting fetchData to null or empty object. Without a url I think
http will gracefully fail. I'm on holiday so can't test at the moment.
If that doesn't work I can add in a check for that next week.
On Nov 21, 2016 21:21, "Petar Slovic" [email protected] wrote:
Hi, I'm wondering if there's a way to turn of the request to /auth/user
that happens after each login?I can see it happening on this line
https://github.com/websanova/vue-auth/blob/master/src/auth.js#L190, and
I tried passing an empty object for fetchPerform and fetchData options,
but it had no effect.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#51, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABkcy0YwbFSSmME7ukUYni_D6BZlCOjeks5rAZq9gaJpZM4K4MSj
.
from vue-auth.
Thanks for the response!
If we pass fetchData
option as an empty object, the fetchPerform
method indeed does an http call without a url. But this means that http service uses just the root url when making that request (e.g. http://localhost/v1/
), which fails and the success callback never gets called, which brakes the login functionality.
I think that the best solution would be to separate the logic of what happens in fetchProcess
into a new method called something like setLoginData
, as this is behaviour that should happen after a successful login:
function setLoginData(data) {
this.watch.authenticated = true;
this.watch.loaded = true;
}
Now we could test if fetchData
option exists, and not perform user fetching if it doesn't, while still getting the successful login behaviour like:
function _fetchProcess(res, data) {
this.watch.data = this.options.parseUserData.call(this, this.options._httpData.call(this, res));
setLoginData(data);
if (data.success) { data.success.call(this, res); }
}
function _loginProcess(res, data) {
var _this = this;
__cookie.set.call(this, data.rememberMe);
this.authenticated = null;
if(this.options.fetchData) {
this.options.fetchPerform.call(this, {
success: function () {
if (data.success) { data.success.call(this, res); }
if (data.redirect && _this.options.check.call(_this)) {
_this.options._routerGo.call(_this, data.redirect);
}
},
});
} else {
this.watch.data = {};
setLoginData();
if (data.redirect && _this.options.check.call(_this)) {
_this.options._routerGo.call(_this, data.redirect);
}
}
}
Would you consider a pull request?
Enjoy your holiday! 🎉
from vue-auth.
Sure can do a pull request, but don't have any way to push up to npm at the
moment :p I'll be back to it Monday :-)
On Nov 22, 2016 15:28, "Petar Slovic" [email protected] wrote:
Thanks for the response!
If we pass fetchData option as an empty object, the fetchPerform method
indeed does an http call without a url. But this means that http service
uses just the root url when making that request (e.g. http://localhost/v1/),
which fails and the success callback
https://github.com/websanova/vue-auth/blob/master/src/auth.js#L191
never gets called, which brakes the login functionality.I think that the best solution would be to separate the logic of what
happens in fetchProcess into a new method called something like
setLoginData, as this is behaviour that should happen after a successful
login:function setLoginData(data) {
this.watch.authenticated = true;
this.watch.loaded = true;
}Now we could test if fetchData option exists, and not perform user
fetching if it doesn't, while still getting the successful login behaviour
like:function _fetchProcess(res, data) {
this.watch.data = this.options.parseUserData.call(this, this.options._httpData.call(this, res));setLoginData(data); if (data.success) { data.success.call(this, res); }
}
function _loginProcess(res, data) {
var _this = this;__cookie.set.call(this, data.rememberMe); this.authenticated = null; if(this.options.fetchData) { this.options.fetchPerform.call(this, { success: function () { if (data.success) { data.success.call(this, res); } if (data.redirect && _this.options.check.call(_this)) { _this.options._routerGo.call(_this, data.redirect); } }, }); } else { this.watch.data = {}; setLoginData(); if (data.redirect && _this.options.check.call(_this)) { _this.options._routerGo.call(_this, data.redirect); } }
}
Would you consider a pull request?
Enjoy your holiday! 🎉
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#51 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABkcyxh0_80LpRDn0oJz5huIB1QJnk4vks5rApmKgaJpZM4K4MSj
.
from vue-auth.
Oh yeah, no worries :) please check out the pull request when you get the time and tell me if there's something that needs to be updated.
from vue-auth.
Hmm, so we only want to disable this on login?
If the fetchData
is set to null it would also fail to load in a few other situations:
- On refresh.
- When calling
fetch()
manually.
It this also intended? There could be two separate concerns here actually.
- Disable user fetch on login (would still occur on refresh and manual calls).
- Disable user fetch completely (but this might kill the manual fetch method).
I know it was mentioned to just set it to null
but after thinking it over, even if disabled having the manual fetch()
call available would still be very useful rather than having to code it in since it's connected to a few things internally.
In the end the plugin will not function without the user data there and it would need to be loaded either by fetch()
or by manually setting user({data})
. Not to mention setting the states internally. Really the internal fetch()
call "SHOULD" be called at some point. Even the check
function will always fail here since the user data is null and it can't perform any role checks.
Might help better to understand what is trying to be achieved here. So you want the user "authenticated" and that's it. Are you ever fetching the user data?
from vue-auth.
Ok, I've setup an initial version of this which I think works quite well and doesn't break any existing code. So you will need to disable fetchUser
in loginData
Vue.use(require('@websanova/vue-auth'), {
auth: require('@websanova/vue-auth/drivers/auth/bearer.js'),
http: require(@websanova/vue-auth/drivers/http/vue-resource.1.x.js'),
router: require('@websanova/vue-auth/drivers/router/vue-router.2.x.js'),
loginData: {
fetchUser: false
},
...
});
NOTE:
- This will disable fetching the user on both login and refresh.
- You can still call
fetch()
manually (preferred way) to fetch the user later on. Which will automatically trigger the watches, etc. - The
fetchUser
can also be disabled as a one off via$auth.login({fetchUser: false});
Also note that this change is in v2.1.0-beta
which is the 2.x stream. This means you also need to now manually set drivers for auth
, http
, router
. Please check the change log for notes.
from vue-auth.
Amazing! Yeah, my use case doesn't require fetching the user. Thanks for the throughout analysis and adding this option!
from vue-auth.
I think this one is good, closing off. thx again for help here :-)
from vue-auth.
Related Issues (20)
- Built in cookie store broken in latest version? HOT 4
- Vue 3 Typescript not working, types missing HOT 1
- Integrate vue-auth with Keycloak HOT 1
- [Question] Authenticating users from external apps HOT 2
- How to set token expiration as refreshData interval HOT 1
- Vue3 Demo - Could not resolve dependency vue@"^3.2.0" from [email protected] HOT 2
- Handling MFA HOT 1
- Support pinia for vue 3 HOT 8
- How to extend Auth using v3 createAuth HOT 4
- This package is not working on VUE 3 + Vite
- token doesn't persist, suggested behavior vs Oauth 2.0 RFC spec? HOT 2
- Vue-Auth and Pinia HOT 10
- Vue 3 rolesKey option not supporting dot notation HOT 3
- redirect to page if i get 503 error HOT 2
- Storing multiple user credentials HOT 1
- Handling multiple roles from different keys HOT 2
- Redirect : Erreur 401 on apache server and not a local wamp HOT 4
- Package not working with Vue.js 3.3 and Vite HOT 1
- Missing Typescript definition for named route params
- Logout request executes after auth reset
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-auth.