Skip to content

Can I pass a custom redirect link to my static login page? #11740

Answered by s-christian
s-christian asked this question in Help
Discussion options

You must be logged in to vote

Not sure why I was having trouble before, but I've figured it out now.

Server Auth Express middleware:

// ...
if (!req.cookies.token) res.redirect(`/login?redirect=${req.url}`);
// ...

Login:

import Router from "next/router";
// ...
function handleSubmit(event) {
    event.preventDefault();
    axios
        .post("/login", { ... })
        .then((response) => {
            // ...
            window.location.href = Router.query.redirect
                ? Router.query.redirect
                : `/users/${response.data.user.username}`;
// ...

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by s-christian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant