Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js is keeping URL hash after response.redirect

I've seen many JavaScript fixes for this using window.location, but nothing for Node.js.

I'm using OAuth to connect users to Facebook. Upon authorization, Facebook redirects to your callback URL and appends "#=" to it. The problem is in my callback route I redirect to another URL, but the URL fragment (hash) is being carried over.

This is my route for Facebook's callback:

exports.facebook_signin_complete = function(req, res)
{
    res.redirect('/profile');
};

If I remove the redirect the URL is /auth/facebook/callback#_=_, and if I keep the redirect the URL is /profile#_=_. Why is the hash being carried over? That's a page specific anchor marker, so I'd be very surprised if that's what it's supposed to do.

like image 660
Gavin Avatar asked Oct 21 '22 06:10

Gavin


1 Answers

The hash in a URL is client-side only, so you can't modify it from the server side of things. When I ran into the same problem I ended up just adding window.location.hash = ''; to the top of my initial JS file.

like image 124
SomeKittens Avatar answered Oct 27 '22 19:10

SomeKittens