Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
new window closing immediately after it opens up

hey folks I have written this code to open up the sign-in page from next-auth library in a new window using the react-new-window library but the problem with this code as soon as I click on the button the new window opens up and it immediately closes

import { useEffect } from "react";
import { signIn, useSession } from 'next-auth/react';

const SignInPage = () => {
    const { data: session, loading } = useSession();
    useEffect(() => {
        if(!loading && !session) void signIn('discord')
        if(!loading && session) window.close()
    }, [ session, loading ])
    return null
}

export default SignInPage
import { useState } from 'react';
import NewWindow from 'react-new-window';
import { signIn, useSession } from 'next-auth/react';
import Button from '@mui/material/Button';
import Box from '@mui/material/Box';

export default function Home() {
  const { data: session, status } = useSession();
  const [popup, setPopUp] = useState(false);
  return (
    <Box>
      <Button color="inherit" onClick={() => setPopUp(true)}>Login</Button>
      { popup && !session ? (
        <NewWindow url='./SignInPage' onUnload={() => setPopUp(false)} />
) : null }
    </Box>
)
}

after doing some debugging I found out that onUnload in

<NewWindow url='./SignInPage' onUnload={() => setPopUp(false)} />

is executing automatically which is not supposed to execute automatically it should be triggered after I get the session please help me in resolving this issue

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda