Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Auth.js · Type Alias

Awaitable

Awaitable<T> is Auth.js's public type for a result that can be supplied immediately as T or asynchronously through PromiseLike<T>. It lets callbacks and provider hooks support either synchronous or asynchronous implementations.

How it works

Awaitable<T> is a union that permits either a value of type T or a PromiseLike<T>. Auth.js uses it for extension points such as callbacks, allowing implementations to complete immediately or return a thenable that resolves to the declared result.

Syntax

type Awaitable<T> = T | PromiseLike<T>;

Key points

  • Awaitable is documented as a public type in the core package's types module.
  • Its generic T describes the result type shared by both allowed branches.
  • Auth.js applies Awaitable to callback return types such as redirect, whose result is a string.
  • JWT callbacks can return either immediately or asynchronously, with null or JWT as the result.

Common mistakes

  • Awaitable is broader than Promise<T>: synchronous values are valid, and the asynchronous branch is PromiseLike<T>, not only native Promise<T>.

Example: Accepting synchronous or asynchronous values

type Awaitable<T> = T | PromiseLike<T>;

const immediate: Awaitable<string> = "done";
const deferred: Awaitable<string> = Promise.resolve("done");

async function readValue(value: Awaitable<string>): Promise<string> {
  return await value;
}

console.log(await readValue(immediate));
console.log(await readValue(deferred));

The same function accepts either an immediate string or a promise-like string, then normalizes both with await.

When to use it

Synchronous callback implementation

An Auth.js callback can compute its result without I/O.

Asynchronous extension point

A callback or provider hook needs database, network, or other asynchronous work.

Flexible API typing

A library function should accept either a direct result or a thenable.

Interview questions

QWhat does Awaitable<T> represent?

Awaitable<T> means T or PromiseLike<T>. It lets an Auth.js callback return its result directly or asynchronously while preserving the result type.

Follow-up: How would a consumer handle both forms? Use await: JavaScript assimilates thenables, so awaiting the value produces T.

QWhy would Auth.js use Awaitable for callbacks?

A callback typed as Awaitable<string> may return a string immediately or a promise-like object resolving to a string. This supports both synchronous and asynchronous implementations without separate callback types.

Follow-up: Why is this useful in library APIs? Callers can provide lightweight synchronous handlers while still supporting I/O-bound handlers.

QWhat is the exact declaration of Awaitable?

The declaration is type Awaitable<T> = T | PromiseLike<T>. The generic parameter T is the eventual logical result, while the union permits either immediate or deferred delivery.

Follow-up: How does it differ from Promise<T>? Promise<T> requires a promise object; Awaitable<T> also accepts T directly and any compatible thenable.

  • Awaited
  • PromiseLike
  • Auth.js callbacks
  • ProfileCallback

Source: Types - Auth.js. Checked 2026-10-15.