# Extended SIWA Diagram

{% @mermaid/diagram content="sequenceDiagram
participant User
participant Client
participant WalletApp
participant NextAuthAPI
participant Server
participant Database

```
User->>Client: Initiate Sign-In
Client->>WalletApp: Request Wallet Connection
WalletApp-->>Client: Return Wallet Address
Client->>Client: Generate SIWA Message
Client->>WalletApp: Request Message Signature
WalletApp-->>Client: Return Signed Message
Client->>NextAuthAPI: Send Signed Message (/api/auth/callback/credentials)
NextAuthAPI->>Server: Verify SIWA Signature
Server->>Server: Validate Signature
alt Signature Valid
    Server->>Database: Create/Update User Session
    Database-->>Server: Confirm Session Created
    Server-->>NextAuthAPI: Return Success
    NextAuthAPI-->>Client: Set Session Cookie
    Client->>User: Display Success Message
else Signature Invalid
    Server-->>NextAuthAPI: Return Error
    NextAuthAPI-->>Client: Return Error
    Client->>User: Display Error Message
end
User->>Client: Access Protected Route
Client->>NextAuthAPI: Check Session (/api/auth/session)
NextAuthAPI->>Server: Validate Session
Server->>Database: Verify Session
Database-->>Server: Confirm Session
Server-->>NextAuthAPI: Return Session Data
NextAuthAPI-->>Client: Provide Session Information
alt Session Valid
    Client->>User: Allow Access to Protected Route
else Session Invalid
    Client->>User: Redirect to Sign-In
end" %}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.siwa.org/general-information/siwa-overview/extended-siwa-diagram.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
