2026-02-25 09:58:15 +01:00
"use client" ;
import React , { useEffect } from "react" ;
import { useSearchParams } from "next/navigation" ;
import { toast } from "sonner" ;
2026-02-25 13:00:52 +01:00
export const ErrorLayout = ({ children } : { children : React.ReactNode }) => {
2026-02-25 09:58:15 +01:00
const url = useSearchParams ();
useEffect (() => {
const error = url . get ( "error" );
if ( ! error ) return ;
const errorMessages : Record < string , string > = {
pending : "Your account is not active." ,
invalid_or_expired_token : "Password reset invalid token." ,
2026-02-25 13:00:52 +01:00
account_already_linked_to_different_user :
"An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address." ,
2026-02-25 09:58:15 +01:00
};
const match = Object . entries ( errorMessages ). find (([ key ]) =>
error . includes ( key ),
);
if ( ! match ) return ;
toast . error ( match [ 1 ]);
const params = new URLSearchParams ( url . toString ());
params . delete ( "error" );
const newUrl =
2026-02-25 13:00:52 +01:00
window . location . pathname +
( params . toString () ? `? ${ params . toString () } ` : "" );
2026-02-25 09:58:15 +01:00
window . history . replaceState ({}, document . title , newUrl );
}, [ url ]);
return <>{ children }</>;
};