identify

Learn how to identify users on the server side.

This function associates the current session with an identified user. It is the server-side equivalent of the client-side identify method.

Call this function when a user authenticates in your application to link their session with their user ID. The SDK issues a signed user token and sets the corresponding cookie.

Signature

This function has the following signature:

function identify(userId: string): Promise<void>

Example

Here is an example of how to use this function in a server API route:

server/api/login.post.js
123456789101112
export default defineEventHandler(async event => {  const body = await readBody(event);
  // Your logic to authenticate the user  const userId = await auth.login(body.email, body.password);
  if (userId !== null) {    await identify(userId);  }
  return {success: userId !== null};})

Parameters

userId
string

The user ID to associate with the current session.