FullAuth

ExamplesTypescriptChangelog

Typescript

In this section, we will cover how to leverage TypeScript to enhance the development experience while using FullAuth in your web, Next.js, React, and React Native applications.

Module Augmentaion:

FullAuth supports TypeScript module augmentation, allowing you to extend existing types with additional properties or methods

Create a fullauth.d.ts file at the types folder in the root of your project: (Next.js or Expo)

types/fullauth.d.ts

import { JWT, Session } from '@fullauth/core';

// decalre module to extend the library type
declare module '@fullauth/core' {
    // jwt containing the user session (when using token strategy)
  interface JWT {
    user: {
      name: string;
      status: 'active' | 'banned';
    };
  }
  // the session object returned by useSession hook
  interface Session {
    user: {
      name: string;
      status: 'active' | 'banned';
    };
  }
}

this will cause the default session to be overwritten with the new defined one.

If you wish to keep the keep the default session propertie, you must merge them with the new props:

types/fullauth.d.ts

import { JWT, Session, DefaultSession, DefaultJWT } from '@fullauth/core';

// decalre module to extend the library type
declare module '@fullauth/core' {
    // jwt containing the user session (when using token strategy)
  interface JWT {
    user: {
      name: string;
      status: 'active' | 'banned';
    } & DefaultJWT["user"]
  }
  // the session object returned by useSession hook
  interface Session {
    user: {
      name: string;
      status: 'active' | 'banned';
    } & DefaultSession["user]
  }
}

Usefull Links