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

369
Vistas
Typescript error: Property 'status' does not exist on type 'never'.ts(2339)

I've currently got a method that looks like this, which uses nextjs/auth to signin with credentials from a form. However, I'm getting a type checking error Object is possibly 'undefined'.ts(2532)

const doStuff = async (values: any) => {
    const result: SignInOptions | undefined = await signIn('credentials', {
      redirect: false,
      password: values.pass,
      email: values.email,
    });
    if (result.status === 200 && result.ok) {
      await asyncDispatcher(
        loginUser({
          email: values.email,
          password: values.pass,
        }),
      );
      router.push(props.redirectLocation);
    }
  };

I (sortof) understand why, if result == undefined then result.status could potentially be undefined and hey ho ERROR. Fine. So then I try this:

const doStuff = async (values: any) => {
    const result: SignInOptions | undefined = await signIn('credentials', {
      redirect: false,
      password: values.pass,
      email: values.email,
    });
    if (result && result.status === 200 && result.ok) {
      await asyncDispatcher(
        loginUser({
          email: values.email,
          password: values.pass,
        }),
      );
      router.push(props.redirectLocation);
    }
  };

I then get Property 'status' does not exist on type 'never'.ts(2339) so then I try to implicitly check for the keys if (result && 'status' in result && result.status === 200 && result.ok) { but this doesn't work either. Anyone know what I'm doing wrong here to get Typescript to play nice?

Under the hood, the definition of signIn (from third party next-auth.js looks like this btw:

export declare function signIn<P extends RedirectableProviderType | undefined = undefined>(provider?: LiteralUnion<BuiltInProviderType>, options?: SignInOptions, authorizationParams?: SignInAuthorisationParams): Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>;

Update for Googlers.

Wrong Response Type - SignInResponse not SignInOptions

Solution:

const result: SignInResponse | undefined = await signIn<'credentials'>('credentials', {
      redirect: false,
      password: values.pass,
      email: values.email,
    });
    if (result && 'status' in result && result.status === 200 && result.ok) {
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I got stuck here too. Nothing seemed to make TypeScript happy here fully.

Your updated solution in the original description still gives me: "Property 'ok' does not exist on type 'never'." errors.

This was the only thing that worked for me:

import type {SignInResponse} from 'next-auth/react';
import {signIn} from 'next-auth/react';

const result = await signIn('credentials', {
    email: data.email,
    password: data.password,
    redirect: false,
}) as unknown as SignInResponse;
about 4 years ago · Juan Pablo Isaza Denunciar

0

One way is to pass in RedirectableProviderType 'credentials' as a type

    const result: SignInResponse | undefined = await signIn<'credentials'>(
  'credentials',
  {
    redirect: false,
    email: enteredEmail,
    password: enteredPassword,
  }
);

if (!!result && result.error) {
  // set some auth state
  router.replace('/account');
}
about 4 years ago · Juan Pablo Isaza Denunciar
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