Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

returnTo not working for me? #339

Closed
tylernix opened this issue Mar 12, 2021 · 9 comments
Closed

returnTo not working for me? #339

tylernix opened this issue Mar 12, 2021 · 9 comments
Labels
question Further information is requested

Comments

@tylernix
Copy link

Is there a specific format that the returnTo parameter is looking for in the LoginOptions being passed into the handleLogin function?

It seems straightforward, but no matter what I do, it always redirects after a successful login to the AUTH0_BASE_URL.

My code:

import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';

let returnTo = process.env.AUTH0_BASE_URL + "/profile";

export default handleAuth({
    async loginHandler(req, res) {
        try {
            await handleLogin(req, res, { returnTo });
        } catch (error) {
            res.status(error.status || 500).end(error.message);
        }
    }
});
@Widcket Widcket added the question Further information is requested label Mar 13, 2021
@adamjmcgrath
Copy link
Contributor

Hi @tylernix - thanks for raising this

Can you try let returnTo = "/profile"; - you don't need to specify a fully qualified url. Security measures should make sure you don't pass in a full URL.

@tylernix
Copy link
Author

@adamjmcgrath I did try that too. Still the same on both localhost and deployed on my own domain.

@adamjmcgrath
Copy link
Contributor

@tylernix - could you also share what version of Next.js, what version of Node and what version of this SDK you are using?

@tylernix
Copy link
Author

Node v14.15.0

"dependencies": {
    "@auth0/nextjs-auth0": "^1.2.0",
    "@tailwindcss/typography": "^0.3.1",
    "autoprefixer": "^10.1.0",
    "bootstrap": "^4.5.3",
    "classnames": "2.2.6",
    "date-fns": "^2.16.1",
    "gray-matter": "4.0.2",
    "next": "latest",
    "postcss": "^8.2.2",
    "react": "^16.13.0",
    "react-bootstrap": "^1.4.0",
    "react-dom": "^16.13.0",
    "remark": "11.0.2",
    "remark-html": "10.0.0",
    "tailwindcss": "^2.0.2"
  },

@adamjmcgrath
Copy link
Contributor

@tylernix Hmmm.. that looks fine. How are you triggering login? Via a link or the withPageAuthRequired helper?

@adamjmcgrath
Copy link
Contributor

adamjmcgrath commented Mar 15, 2021

Ah, actually - I've spotted the issue

export default handleAuth({
    async loginHandler(req, res) {

handleAuth takes a login property to override the login handler, eg

export default handleAuth({
    async login(req, res) {

@tylernix
Copy link
Author

Ahhh! Beautiful! It worked.

I copied and pasted that code from somewhere, but I just went back to handlers/login, and it does have the right code. 👍 Could this possibly have changed from the beta documentation to the latest 1.2.0 release? I have been working with this since the beta, so that is the only way I could explain things. Thanks again for your help!

@adamjmcgrath
Copy link
Contributor

Cool, glad you got it working @tylernix

Could this possibly have changed from the beta documentation to the latest 1.2.0 release?

The behaviour hasn't changed - but there could be a bad example out there somewhere, if you spot it let me know

@tylernix
Copy link
Author

I'll keep an eye out. But I haven't been able to find it in my last few minutes of searching, so maybe I am just crazy. I know at some point I had imported loginHandler from back during the beta (//import { loginHandler } from '@auth0/nextjs-auth0/dist/auth0-session';) because it is still in my comments, but I can't find a single reference to it anymore, so I guess that is a good thing.

Thanks again for your help! I have enjoyed working with nextjs-auth0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants