Ok. I think I'm understanding better now.
After requesting the refresh token with the code, my url only redirects with the same code. This is difficult to explain, but I am able to return all data except the refresh token.
So it sounds like the code
is coming back with the redirect and things are stopped right there. Assuming code
is returned correctly, then we should be hitting this:
let code = req.query.code;
if (code) {
Your POST
looks good to me which means you're getting here:
//let qs = "access_token=" + results.access_token + "&refresh_token=" + results.refresh_token + "&username=" + results.username;
res.render('customize', { title: "appname", username: results.refresh_token, refresh_token: results.refresh_token });
// results.refresh_token returns undefined?
the res.render
is sending you to http://localhost:3000/customize?code=longcodeherebutpopulatedwithactualcode
This is where there's some additional confusion. The route described is:
router.get('/', function(req, res, next) {
However, the url ends up being:
http://localhost:3000/customize?code=longcodeherebutpopulatedwithactualcode
Somehow, we're getting to another route. res.render
should just be rendering a template, right?
What does the /customize
view looks like. Is it also handling code
? It just looks like some weird thing is happening where it's not sending the right data, but code
again. I'm trying to see why that is, but I don't see why the customize
template would change the URL.
Sorry for the confusion. The code I sent above is in
customize.js
Below is a screenshot from webstorm of my file structure. the file currently opened isapp.js
put simply,
router.get('/', function(req, res, next)
in customize.js applies tolocalhost:3000/customize
Ok. I'll need to go through this and see what's in
results
. It's possible this tutorial needs updating since it's so old. LOL.Haha no worries. That would be great, thanks again!
I hope you already resolved your problem but if not - just remember you need to pass
offline
scope to get refresh_token. Otherwise it will be undefined.I was not aware of this. THANK YOU so much!