Search code examples
next.jsnext-auth

Next-Auth signOut function leads to 127.0.0.1


I am using next js next-auth signOut function whenever i try to signOut from logged in session this function leads me to 127.0.0.1 and show error 127.0.0.1 refused to connect. I don't know why it should leads me to login or other page. if any one have solution it will be greate confort for me. Here is the Logout component where i am using this signOut function

"use client";
import React from "react";
import { signOut } from "next-auth/react";

    const Logout = () => {
      return (
        <div>
          <button
            type="submit"
            onClick={() => signOut()}
            className="bg-indigo-700 p-2 rounded-md"
          >
            Logout
          </button>
        </div>
      );
    };
    
    export default Logout;

Solution

  • After signing out You'll be redirected to the NEXTAUTH_URL environment variable. Make sure to set it as your website URL.

    signOut()
    // will redirect to proccess.env.NEXTAUTH_URL or localhost:3000
    

    If you want to redirect to a specific page (e.g. /login) set the callbackUrl prop:

    signOut({ callbackUrl: "/login" })
    // will redirect to (process.env.NEXTAUTH_URL + callbackUrl)