Skip to content

useSignIn

Import

import useSignIn from 'react-auth-kit/hooks/useSignIn';

Function Signature

useSignIn<T>(): (signInConfig: signInFunctionParams<T>) => boolean

Sign In React Hook

Call the hook to sign In and authenticate the user

This will authenticate the user by writing the user state into the memory Also, this will call the RX engine to store the auth in the storage

Type Parameters

Name Description
T Type of User State Object

Returns

React Hook with SignIn Functionality

fn => (signInConfig): boolean

Parameters

Name Type Descripntion
signInConfig signInFunctionParams<T> Params for signin

signInConfig Parameters

Name Type Descripntion Required
auth.token string JWT Auth Token true
auth.type string Type of the Token false
refresh string JWT Refresh Token true
userState T User Data false
{
  auth : {
    token: 'ey.........o1',
    type: 'Bearer'
  },
  refresh: 'ey..........92',
  userState: {
    name: 'The Dev'
    uuid: 'fff-fff-ffff'
  }
}

Example

Here's an example without the refresh token:

import useSignIn from 'react-auth-kit/hooks/useSignIn'

const LoginComponent = () => {
 const signIn = useSignIn()
 signIn({
   auth: {
     token: '<jwt token>'
   },
   userState: {name: 'React User', uid: 123456}
 })
}

Here's an example with a refresh token in TypeScript:

import useSignIn from 'react-auth-kit/hooks/useSignIn'

 interface IUserData {
 name: string;
 uuid: string;
};

const LoginComponent = () => {
 const signIn = useSignIn<IUserData>()
 signIn({
   auth: {
     token: '<jwt token>'
   },
   userState: {name: 'React User', uid: 123456},
   refresh: <refresh jwt token>
 })
}

Remarks

If you are using the refresh token, make sure you add that in the parameter, else it throws AuthError

If you are not using the refresh token, make sure you don't include that in the parameter, else it throws AuthError.

Throws

AuthError

  • Thrown if the Hook is used outside the Auth Provider Scope.
  • Thrown if refresh token is added, despite not being used.
  • Thrown if refresh token is not added, is spite used.

Defined in

hooks/useSignIn.ts


— 🔑 —

React Auth Kit is MIT License code