I want to access context variable to use the isMobile flag to select a different endpoint depending on the result. I could pass it on the dispatch from the component, but I know there should be one way to do it.
export const actions = {
...
signUpGoogle({ commit }) {
fireauth.useDeviceLanguage()
if (context.isMobile) {
fireauth.signInWithPopup(GoogleProvider).then ...
} else {
fireauth.signInWithRedirect(GoogleProvider)
}
}
I saw here that it can be obtained on server init, but I really don't want to rely on this as caching will mess things up
https://nuxtjs.org/guide/vuex-store/#the-nuxtserverinit-action
Thanks for the help
I'm not sure if you're talking about an environment variable here, but below is the answer if it is.
Looking on this GH issue, we can find out that you can use this.app.$config.isMobile (basically referencing env variables aka publicRuntimeConfig values in your nuxt.config.js).
You can do one thing in nuxtServerInit, set this variable in state using the context, and then use state.isMobile to do this type of API Calls. Hopefully, that should solve this.
If it's not very clear, I can edit to give some code examples
Related
Is it a good idea to use function name property instead of constants for actions/mutations, like the code below?
Author of Vuex official documentation says that it is not required to use constants for actions/mutations. So I want to try to use type is based on function name.
Component:
this.$store.dispatch(authActions.login.name, {
email: this.email,
password: this.password
})
Action:
async login(context, { email, password }) {
// some code
}
I am waiting for the following answers:
1) Yes, you can use it, there are no potential problems with this
approach.
2) Yes, but these problems [problems] can happen.
3) No, there are a lot of problems: [problems].
I think it's option number 2).
The problem comes when you want to dispatch namespaced modules actions.
You can do this and it does work, but I noticed when I minify my code for production it stops working.
I suspect there's some code that maps the function names (ie login()) to their minified version (ie h()) during bundling, and that's breaking things.
I've been trying to figure this out for a while with no luck. I agree defining constants to use as function names, instead of grabbing the name after like myFunction.name, is stupid. I'll update my comment if I figure it out. I'll keep trying...
I am using laravel for my backend api.
My question is about an scopefilter, the problem is that it is not responding when I call to it.
I have a lot of examples for using scopefilters.
So I looked at each of them to see if I did something wrong.
But I can't seem to find the problem.
When I call to this model in laravel, I use a parameter to define too the scopefilter to use a specific function.
The point only is that it never gets to this function, I don't get a response when I have put a log in this function.
I assume it is a syntax problem but maybe someone else can find the problem for this.
public static $scopeFilters = [
"supplierArticleClientId" => "bySupplierArticleClientId"
];
public function scopeBySupplierArticleClientId($query, $clientId) {
\Log::info([$clientId]);
}
In this case I expect that I see an clientId in my log.
You have to create a Custom validation function Implementing Rule Class
please go through this link for reference
I have built a very simple react-native redux app with redux-thunk. When i run my app, i run into the error 'actionTypes is undefined'. Error and the line where the error is.
The app isnt anything to big, just has one action creator file and one reducer file with another index file. Been stuck on this for a couple of day. Anyone that can help, itll be greatly appreciated. Thank you!
Are you exporting from actionTypes.js? Every single type you define there would need to be exported separately.
But do not use the 'default' keyword like you do in your reducer. That's used in the case that you have one thing to export.
I assume you are storing all of your action related const variables in actionTypes.js.
When defining them, you need to export them from the file itself, in order to use them from within another file. I think the code you've provided is fine, but my guess is you are not exporting FETCH_DATA in this case. EG - in actionTypes.js
export const FETCH_DATA = "FETCH_DATA";
...
... // other variables can be done the same way
and so on.
Hi i need some help for this issue, I need to run:
exports.someFunction = function () {
// i need call a route like this.
app.route('api/getdata');
};
I need call some route in express function. How can I do it?
I'm assuming that /api/getdata returns some sort of data (in a format like JSON) you need to use. In that case, it is pretty simple, just use Node's excellent unirest library. I find Node's http a little advanced for this case. Assuming that this is a GET request, it would look something along the lines of:
unirest.post('http://example.com/api/getdata').end(function (response) {
console.log(response.body);
});
Of course, you can use Node's http.get if you wanted or any other HTTP library you like.
This is essentially a continuation of the question here: Nodejs Passport display username.
app.get('/hello', function(req, res) {
res.render('index.jade', { name: req.user.username });
});
So users log in via PassportJS, and goes to index.jade, which contains #{name} in the body, which will be replaced by the value of req.user.username.
Question: Is it possible to use the value of req.user.username in index.jade's JavaScript? I tried assigning its value to a variable but it doesn't work.
I have been using the trick of having a hidden input with #{name} as value:
input(type='hidden', id='variableName', value='#{name}')
Then JavaScript can access this value using:
$("#variableName").val()
This works. But does it have any potential downside like security issues? What is the right way to do this?
You have a few options. One of them is what you did and put the value inside you html. You can also solve it by doing:
script
window.name = #{name};
This will create an inline script that sets the variable. The other option you have is using ajax. That means you probably need to make an extra route to reply to that request.