Routing & redirecting with iron-router - meteor

How does one do an official redirect to another route from a Template.event call using meteor and Iron-Router. I seem to, at least with the Dev branch run into the same error
`if (this._isRunning) // 174
throw new Error('Already in a page run'); `
As an example, i have a button that on click calls Router.go('/home'); if i run this, i get the 'already in a page run' error. Anyone else routing with the router go method?
Its actually the 'this.redirect('/anotherpath')' that causes the problem. Is there way to stop the current running page run and redirect to another route?

It looks like you're working off of the dev branch. The code you were working with has been rolled back because it wasn't working properly. If you still have the issue let me know, and sorry about that!
The code below will stop the current route controller from running (stop any downstream hooks and the action method from being run) and call Router.go('/anotherpath') which will cause a new route to run.
this.redirect('/anotherpath')

Related

Symfony routes not working anymore

I have an application been working on for a while with a fully working login and creating new users functionalities, and out of no where i was trying to switch the user -to change the role- i wasnt able to login again. after some digging around the code i found out that 302 code status is being thrown after login and therefor the logging process stopped working.
i had this code in my SecurityController:
return new RedirectResponse('/sys-admin/');
and changing that code to this :
return $this->forward('AppBundle:SystemAdmin:index', array());
make it work and i am logged in again but now all my routes stopped working, i mean in my views there are buttons something like :
<a href="{{ path('system_admin_client') }}"
class="btn pmd-btn-flat btn-default">Go!</a>
when i click the button i am logged out and redirected to the login page and in the network tab in any browser i can see that the route sys-admin/client have status code 302 since i was logged out.
running bin/console debug:router shows me all my routes are there and for this example running bin/console router:match /sys-admin/client also shows me a match with the controller and every information.
this is how my routes looks like:
app_system_admin:
prefix: /sys-admin
resource: "#AppBundle/Resources/config/routing/sys_admin.yml"
sys_admin.yml
system_admin_client:
path: /client
defaults: { _controller: AppBundle:SystemAdmin:index}
I cant figure out to know what went wrong! any help will be appreciated. Thanks!
more info: i am using Symfony 4.0.4 and if i tried to do something like forwarding on any route its working but the redirecting is not.
The 302 HTTP status code is for a redirection, it's not an error.
It was normal since you returned a RedirectResponse.
In my opinion the problem doesn't come from the redirection.
You should put it back and check the user-switching function (or the user itself).
If you do that, don't hardcode the redirection path. Use a Symfony method to generate it, like:
return $this->redirectToRoute('system_admin_index');
I found the solution after a lot of investigating. I am using docker to make the whole app running and for some reason php-fpm logs showed no errors but the error was the php session is being broken because of no access for the user, changing to root user on docker fixed this issue since root had access.

How do I resolve the Google OAuth "redirect_uri_mismatch" error?

I am failing to configure my Google OAuth for my Meteor app.
I was successful in setting it up a few weeks ago when it worked perfectly, but now all of a sudden I cant seem to correctly configure this.
I have tunneled my app via ngrok. Am going to give you a step by step illustration of the how I go towards setting this up. Kindly point out what am doing wrong and what I can do to rectify this.
I start in my terminal. I fire up the app using:
meteor --port 7000
I open up another terminal and fire up ngrok using:
./ngrok http 7000
This yields
In my Meteor.startup I add the following code:
../client/main.js
Meteor.startup(function () {
// Client startup method.
METEOR_OFFLINE_CATALOG=1;
METEOR_PROFILE=1;
Meteor.absoluteUrl.defaultOptions.rootUrl ='http://41958975.ngrok.io';
//
});
In my browser console when I type:
Meteor.absoluteUrl()
I get
I now paste the http://41958975.ngrok.io link into the browser and get this:
Clicking on the button is followed by:
Since the steps 1 to 5 have previously been done, I jump straight to steps 6, 7, and 8.
...and complete by pasting in the Client ID and the Client Secret
then clicking on the save configuration. The results is:
Now when I click on the sign in with google button: This pops up, just like its supposed to happen.
I click on one of the account options. This is when it all goes bazurk! I am redirected back to the sign in with google button (login page) with this error message showing
Looking at the terminal, I also get this error message:
I cant seem to get beyond this point.
What am I doing wrong and how can I get beyond this point?
Looking forward to your help.
You forgot to modify your ROOT_URL when you're running your app. The very first line of your last screenshot clearly shows it:
App running at: http://localhost:7000/
Setting absoluteUrl on client won't help, because it's your server who tries to obtain a token.
It uses OAuth._redirectUri() function to get redirect_uri, and there the Meteor.absoluteUrl() is used (it takes ROOT_URL from env variables, as stated in documentation).
Thus, your redirect_uri becomes http://localhost:7000/_oauth/google and that clearly mismatches with http://41958975.ngrok.io/_oauth/google (step #7).
To fix that you should start your Meteor application like this:
ROOT_URL="http://41958975.ngrok.io" meteor

How to test receiving a Stripe webhook using ngrok

I can successfully send a web hook from Stripe to my Meteor app in development using ngrok. For example, my test endpoint on the Stripe dashboard would be sent to something like https://f5f62fdf.ngrok.io. It responds with a successful notice. The ngrok inspector shows the stripe test object received. But in Meteor I'm a little unsure how the router should look with ngrok. On the server, my route would be something like:
Router.route( "<unsure what path to put here>", function() {
console.log('hello');
}, { where: "server" });
In my testing environment using ngrok, what would the path be?
Just trying to get the function to console.log() my 'hello' so I know it's working.
OK, I'm an idiot. It console.logs to the terminal, not the browser. Ouch. Given I'm working with Node, it makes sense. Just for posterity, the Stripe endpoint would be something like https://g4r62fdf.ngrok.io/stripe/webhook.
Make sure you're returning a response inside the function so the web hook won't timeout.
this.response.statusCode = 200;
this.response.end('10-4, good buddy');

Where to declare collections when files are split between server and client directories?

I am struggling with Meteor when using separate client and server directories and was hoping someone could help me.
My server code in the server subdirectory looks like:
Testing = new Meteor.Collection("testing");
Testing.insert({hello1:'world1'});
Testing.insert({hello2:'world2'});
Testing.insert({hello3:'world3'});
Meteor.publish("testing", function() {
console.log('server: ' + Testing.find().count());
return Testing.find();
});
My client code in the client subdirectory looks like:
Meteor.subscribe("testing");
var Testing = new Meteor.Collection("testing");
console.log('count: ' + Testing.find().count());
I have tried this with autopublish on and off.
In my terminal window, I can see the log statement output a number of items as I would expect. But for my client, in the browser console window I always see a count of 0.
Not sure if this is related, but when I modify my subscribe statement and save my changes, I see this error in my console window:
POST http://localhost:3000/sockjs/574/ukpxre9v/xhr 503 (Service Unavailable) sockjs- 0.3.4.js:821
AbstractXHRObject._start sockjs-0.3.4.js:821
(anonymous function)
I'm sure I'm making some stupid mistake, but I haven't had any luck tracking it down. Any help would be greatly appreciated.
You're running console.log('count: ' + Testing.find().count()); too soon Meteor will sync your server collection down to the client but it takes a very short amount of time.
For instance you could run console.log('count: ' + Testing.find().count()); in your web console it should give you a proper result because you would have waited half a second or so for it to load the data down from the server.
You could put this code in a reactive context so it shows the live count correctly, such as Meteor.autorun or a Template helper.
The reason you see that 503 XHR error is when you modify your code and save it, meteor restarts and serves up the new content asap, so the socket between the client and server is temporarily interrupted, until it refreshes the page. This is not really anything wrong with your code.

weird problem - OAuthException - Access Token

Yesterday I noticed problem with my application. Everything was fine, but now something is wrong with button and postbacks.
I get error:
(OAuthException) (OAuthException) An active access token must be used to query information about the current user.
while im trying use .Get("me") info # postback.
I set a watch on reguest.params(signed_request) and everyting is fine, but when I click button on my app to make postback, my request.params(signed_request) value is nothing.
Any ideas how to solve problem ?
(im using 4.2.5 (?) sdk and 5.0.6 show me the same error)
Pass access token parameter to FacebookWebClient constructor:
new FacebookClient(FacebookWebContext.Current.AccessToken);

Resources