> ## Documentation Index
> Fetch the complete documentation index at: https://turnkey-0e7c1f5b-andrew-prettier.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Learn how to set up authentication that leverages Turnkey's Auth Proxy using @turnkey/core in your frontend JavaScript application.

## Triggering authentication

You can call the specific login or signup methods you want to support. For example, with passkeys:

```ts theme={"system"}
// Log in with a passkey
const session = await turnkeyClient.loginWithPasskey();

// Or sign up with a passkey
const session = await turnkeyClient.signUpWithPasskey();
```

Here's an example using email OTP:

```ts theme={"system"}
// Log in with email OTP
import { OtpType } from "@turnkey/core";

const otpId = await turnkeyClient.initOtp({
  otpType: OtpType.Email,
  contact: "email@example.com",
});
const session = await turnkeyClient.completeOtp({
  otpId,
  otpCode: 123456, // The code the user received via email or SMS
  contact: "email@example.com",
  otpType: OtpType.Email,
});
```

Sessions will be automatically created and stored in the browser's local storage or mobile async storage on React Native.

## Checking authentication state

To check if a user is authenticated, call `client.getSession()` and verify the expiry:

```ts theme={"system"}
const session = await turnkeyClient.getSession();

if (session && session.expiry \* 1000 > Date.now()) {
    console.log("User is authenticated:", session);
} else {
    console.log("User is not authenticated");
}
```

If the session is expired or the user is done with their session, you can log them out:

```ts theme={"system"}
await turnkeyClient.logout();
```
