<p>
   Magic URL is a password-less way to authenticate users. 
   When a user logs in by providing their email, they will receive an email with a "magic" link that contains a secret used to log in the user.
   The user can simply click the link to be logged in.
</p>

<h2><a href="#init" id="init">Send Email</a></h2>

<p>
    Initialize the log in process with the <a href="/docs/client/account#accountCreateMagicURLSession">Create Magic URL Session</a> route.
    If the email has never been used, a <b>new account is generated</b>, then the user will receive an email. 
    If the email is already attached to an account, the <b>user ID is ignored</b> and the user will receive a link in their email.
</p>

<ul class="phases clear" data-ui-phases>
    <li>
        <h3>Web</h3>
        <div class="ide" data-lang="javascript" data-lang-label="Web SDK">
            <pre class="line-numbers"><code class="prism language-javascript" data-prism>import { Client, Account, ID } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('[PROJECT_ID]');                 // Your project ID

const account = new Account(client);

const promise = account.createMagicURLSession(ID.unique(), 'email@example.com');

promise.then(function (response) {
    console.log(response); // Success
}, function (error) {
    console.log(error); // Failure
});</code></pre>
        </div>
    </li>
    <li>
        <h3>GraphQL</h3>
        <div class="ide" data-lang="graphql" data-lang-label="GraphQL">
            <pre class="line-numbers"><code class="prism language-graphql" data-prism>mutation {
    accountCreateMagicURLSession(
        userId: "ID.unique()",
        email: "email@example.com"
    ) {
        _id
        _createdAt
        userId
        secret
        expire
    }
}</code></pre>
        </div>
    </li>
</ul>

<h2><a href="#login" id="login">Log In</a></h2>

<p>
    After receiving your secret from an email, you can create a session.
</p>

<ul class="phases clear" data-ui-phases>
    <li>
        <h3>Web</h3>
        <div class="ide" data-lang="javascript" data-lang-label="Web SDK">
            <pre class="line-numbers"><code class="prism language-javascript" data-prism>import { Client, Account } from "appwrite";

const client = new Client()
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('[PROJECT_ID]');                // Your project ID

const account = new Account(client);

const urlParams = new URLSearchParams(window.location.search);
const secret = urlParams.get('secret');
const userId = urlParams.get('userId');

const user = await account.updateMagicURLSession(userId, secret);</code></pre>
        </div>
    </li>
    <li>
        <h3>GraphQL</h3>
        <div class="ide" data-lang="graphql" data-lang-label="GraphQL">
            <pre class="line-numbers"><code class="prism language-graphql" data-prism>mutation {
    accountUpdateMagicURLSession(
        userId: "unique()",
        secret: "[SECRET]"
    ) {
        _id
        _createdAt
        userId
        expire
        provider
    }
}</code></pre>
        </div>
    </li>
</ul>