Stripe Elements JS redirect user - javascript

I'm following the guide on Stripes docs https://stripe.com/docs/billing/subscriptions/fixed-price
Everything works, I just cannot work out how to actually redirect the user from the JS
function onSubscriptionComplete(result) {
// Payment was successful.
if (result.subscription.status === 'active') {
console.log('redirect');
location.href = 'https://google.com';
}
}
Here the console is logging redirect but the user is not redirected. What is the best way to redirect the user after confirming the payment?

Related

JS/Jquery and firebase login page issues

I am trying to build a login page. After a user has logged in correctly I want to exit the index.html page and redirect to my portfolio.html page.
firebase.auth().onAuthStateChanged(user => {
if(user) {
window.location = 'portfolio.html';
} else {
// No user is signed in.
// window.location = 'index.html';
console.log("Not logged in");
}
});
The code above does switch pages, but then constantly reloads the page over and over again in a loop. I am very stuck friends:(.
Thank you for your time.
Isn't it like, you got redirected to portfolio.html, the auth code is exectuted, the user object is already there, so it redirects you to portfolio again. Try adding
if(window.location.indexOf("portfolio.html") === -1){
//redirection here
}
I guess the problem is that the piece of code is also executed in your portfolio.html. So when the page is loaded, firebase checks if there is a user logged in from web storage and in your case, the user is logged in previously. So the listener will be triggered again and reload the page.

how to prevent user from accessing webpage directly in node.js?

Hello I am having an issue preventing a user from accessing my site by typing in the URL. I have a login which I want to be the only way to access my /factory/homepage.html page.
But if a user types /factory/homepage.html into the URL field, they can access the homepage.html.
Im already using app.get('/factory/'), but my res.redirect('/website/userLogin.html') does not redirect to the login page.
Here is my code:
app.get('/factory/*', function(req,res,next){
console.log("going through app.get...");
res.redirect('../website/userLogin.html');
console.log('after redirect...');
});
The output is:
going through app.get...
after redirect...
And the user is taken to factory/homepage.html. I also tried app.use('/factory/*'), but no luck. The redirecting only works if a path that doesn't exist in my factory directory is entered, for example /factory/hello.html will redirect to /website/userLogin.html
I'll like for the directory /factory to not be accessible through typing in the url. Then after i will implement a middleware function to check if the user is authenticated.
Any help will be appreciated!
I'd try something like this.
app.get('/factory/*', function(req,res,next){
var authenticated = false;
//do something to authenticate user
if(authenticated === true){
//user is already authenticated
res.redirect('/factory/homepage.html');
}else{
//redirect to login
res.redirect('../website/userLogin.html');
}
});

Meteor.js redirect to "dedicated" page before email is verified

I have this logic that I'm trying to implement and I'm failing to do so... Here is the deal. I have implemented the confirmation mail for new users and now with the code that I will paste bellow I'm basically blocking the user from login into the app before he confirms he's email address. Okay fairly clear. But now I want to send him to a dedicated "verifiaction" page where it will only be some kind of text like "You need to verify you email before you can login, click to resend the confirmation link, blablabla". Im also using iron router.
Im doing this for the check:
//(server-side) called whenever a login is attempted
Accounts.validateLoginAttempt(function(attempt){
if (attempt.user && attempt.user.emails && !attempt.user.emails[0].verified ) {
console.log('email not verified');
// Router.go('verification'); - some kind of my "logic" what I want to
}
return true;
});
There is a discussion with the same issue here and in the comments, a user suggests resending the verify email token and alerting the user, instead of redirecting to a page, which would be simpler. The code for that would look like:
Accounts.validateLoginAttempt(function(attempt){
if (attempt.user && attempt.user.emails && !attempt.user.emails[0].verified ) {
Accounts.sendVerificationEmail(user._id);
Alert('Your email has not been verified, we have re-sent the email. Please verify before logging in.');
//you could also use a modal or something fancy if you want.
}
return true;
});
If definitely want to create a page, there is an answer here about ways to do that, but how you do it it depends on whether you want it to be part of the layout or not.

FB.logout() - no access token - "Log in as Different User"

This question is in relation to this question: FB.logout() called without an access token
I had a question i was hoping someone could help with.
I get everything in the link above, but how do you handle when someone uses a public computer and leaves themselves logged in to FB by accident? Then a new user tries to log in to an app, but it is not them. I want to have a button to log them out of FB altogether to "log in as a different user".
I cannot do that until they authorize the app, right? So they need to authorize the app under someone else's account and then log out? There has to be another way.
Any feedback would be great - tried searching for a while on this, but to no avail. I might be over thinking it, but there should be some way to "log in as a different user".
You can do something like:
FB.getLoginStatus(function(response) {
if (response.status === "connected") {
FB.api("me", function(response2) {
// notify the user he is logged in as response2.name, and if it's not him call FB.logout
}
}
else {
// prompt the user to login
}
}
Modify your logout to something like this :-
function logout(response){
console.log("From logout" + response);
if(!response.authResponse){
window.location = "/web/login/";
return;
}
FB.logout(function(response){
FB.Auth.setAuthResponse(null,'unknown');
logout();
});
}
i.e keep on sending logout request to Facebook till the actual logout happens.
Try to use Session and save the user's ID in that session.
You can control the expiration time of that session( by default its 20 minute if the user doesn't have any activity on the page)
then in each page Load even check whether the season is still active for that user or not.
page Load event:
if(Session["LoggedIn"]==null)
{
Response.Redirect("~/Login.aspx");
}
This code above will redirect user to login page of your website if the session has expired.

Prompt-Permission on facebook?

I am having trouble of understanding how the fb:prompt-permission work. I can have a link appear when the user click the fb:login-button either the user already logged in from facebook to our application or through our website. On the other hand, without clicking the login-button, the link or the permission dialog doesn't render if the user already logged in from facebook to our page.
Doesn't that mean prompt-permission only available when the user clicks the login button ... Is there a way to avoid that?
Use this:
<fb:login-button perms="publish_stream, email">Login and Install</fb:login-button>
Source: http://developers.facebook.com/docs/guides/web
Use the standard FB Connect loginbutton, add on onlogin() function call
<fb:login-button onlogin="OnRequestPermission();"></fb:login-button>
and use this function to manually invoke the permission request dialog :
function OnRequestPermission(){
var myPermissions = "publish_stream"; // permissions your app needs
FB.Connect.showPermissionDialog(myPermissions , function(perms) {
if (!perms)
{
// handles if the user rejects the request for permissions.
// This is a good place to log off from Facebook connect
}
else
{
// finish up here if the user has accepted permission request
}
});
}
Source: http://forum.developers.facebook.com/viewtopic.php?pid=190797

Categories