# User Identity > Sign users in with a signed token, and understand the device ID the QwryAI Android SDK keeps ## Overview The SDK knows who it's talking for in one of two ways: | Layer | How it works | Conversations belong to | | - | - | - | | **Device ID** | Automatic: made on the first launch | This install of your app | | **User identity** | Opt-in: pass a signed token to `identify()` | The user, on every device they sign in on | The SDK works anonymously from the start. Call `identify()` when a user signs in to your app. ## Device ID Every install has a stable device ID: ```kotlin val deviceId: String ``` ```kotlin val client = Qwry.create(context, "YOUR_AGENT_ID") println(client.deviceId) // a random UUID, the same on every launch ``` > [!NOTE] > > The device ID is a random UUID that the SDK makes once and keeps in your app's private storage (`SharedPreferences` named `qwryai_sdk_prefs`). It survives app restarts and is reset when the app is reinstalled or its data is cleared. ## identify `class QwryClient`, **Package:** `com.qwryai.sdk` ```kotlin suspend fun identify(token: String): String ``` Sends the token to QwryAI to check it, signs the user in, and returns their user ID. From then on, every request is made as this user. Conversations this device started anonymously move to the user before `identify()` returns. **token** `String` *required* A JWT that your server signs with HS256 using your agent's identity verification **Secret key**. Its payload must hold a `user_id` (or `sub`) claim. See [Identity verification](/docs/developer-guides/website-integration/identity-verification) for where to find the secret. **1. Sign a token on your server** Make the JWT on your own server, never in the app, so the secret never ships inside your APK. ```javascript // Node.js, with the jsonwebtoken package const token = jwt.sign({ user_id: user.id }, process.env.QWRYAI_IDENTITY_SECRET, { algorithm: "HS256", expiresIn: "1h" }); ``` **2. Pass the token to the SDK** ```kotlin val userId = client.identify(tokenFromYourServer) ``` Conversations now belong to this user. **3. Check who the SDK is talking as** ```kotlin println(client.authState.value is AuthState.Identified) // true println(client.currentUserId) // the user_id from the token ``` > [!NOTE] > > The token is kept in your app's private storage, so the user stays signed in across launches. It's sent with every request and checked each time: once it expires, calls fail with `401` `AUTH_INVALID_JWT`. Get a fresh token from your server and call `identify()` again. ## Identity properties ```kotlin val deviceId: String ``` This install's ID. Always available. ```kotlin val authState: StateFlow ``` Who the SDK is talking as: `AuthState.Anonymous`, or `AuthState.Identified(userId)`. Collect it to update your UI when a user signs in or out. ```kotlin val currentUserId: String? ``` The signed-in user's ID, confirmed by the server. `null` while anonymous. ### AuthState `sealed interface AuthState`, **Package:** `com.qwryai.sdk` ```kotlin sealed interface AuthState { data object Anonymous : AuthState // conversations belong to this device data class Identified(val userId: String) : AuthState // conversations belong to this user } ``` ## How identity affects conversations > [!NOTE] > > While a user is identified, `listConversations()` returns that user's conversations from every device and from both mobile SDKs. While anonymous, it returns only this install's conversations. `identify()` also clears `currentConversationId`, so the next `send` starts a new conversation as the user. ## logout ```kotlin fun logout() ``` Forgets the token and goes back to this device's own anonymous conversations. Also clears the current conversation, so the next message starts a new one. ```kotlin client.logout() println(client.authState.value) // AuthState.Anonymous println(client.currentUserId) // null println(client.currentConversationId) // null println(client.deviceId) // unchanged ``` > [!NOTE] > > Conversations that moved to the user when they signed in stay with the user after `logout()`. The device starts again with no anonymous conversations of its own. ## Related > [card] Conversations & History | /docs/android-sdk/conversations | List conversations and load earlier messages. > [card] Overview | /docs/android-sdk/overview | What the SDK does and its limits.