Skip to content

NylasConnect.getSession()

NylasConnect.getSession() retrieves the complete session data for a grant, including tokens and user information.

// Get session data for current grant
const session = await nylasConnect.getSession();
// Or for a specific grant
const session = await nylasConnect.getSession('<NYLAS_GRANT_ID>');

You can pass no parameters to the method if you want to check the grant associated with the current session. If you want to check a specific grant, pass it as a parameter.

ParameterTypeDescription
grantIdstring?The ID of the grant to access. If not provided, Nylas Connect uses the grant ID associated with the current session.

The getSession() method returns a Promise<SessionData | null> with the following properties.

PropertyTypeDescription
accessTokenstringThe access token associated with the grant.
expiresAtnumber?When the access token will expire, in seconds using the Unix timestamp format.
grantIdstringA unique identifier for the user’s grant.
grantInfoGrantInfo?Optional grant information from the idToken.
idTokenstring?An ID token containing user information.
refreshTokenstring?An optional refresh token used to renew access tokens.
scopestring?A space-delimited list of scopes associated with the user’s grant.
PropertyTypeDescription
emailstringThe email address associated with the grant.
emailVerifiedboolean?When true, indicates that the user has verified their email address.
familyNamestring?The user’s surname (last name).
givenNamestring?The user’s given (first) name.
idstringA unique identifier for the user’s grant.
namestring?The user’s display name.
picturestring?A URL that links to the user’s profile picture.
providerstringThe OAuth provider that the user authenticated with.