Next.js Discord

Discord Forum

NextResponse.redirect directs me to login page

Unanswered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
is there a better way to redirect because i think its because the cookies get removed?
import { NextResponse, NextRequest } from 'next/server';
import { redirect } from 'next/navigation'

export async function POST(req: NextRequest) {
    const res = await req.formData()
    const coins = res.get('coins')
    const artist_id = res.get('artist_id')
    console.log(coins, artist_id)

    return NextResponse.redirect(new URL('/trade', req.url))
}

4 Replies

Please explain more, what are you trying to do, and where do you want to redirect to
American black bearOP
so i have a page where a user fills a form and teh from redirects him to the api adn with the api i want to read out the data and wont to write it in a DB and the i want to redirect the user back to the page
European sprat
Return a response which the client reads and redirect on client? I think what you're doing above is redirecting the POST request
American black bearOP
Redirect the Client but i dont want to lose the Cookies