> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portalhq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# getMagicLinkDetails

> Reads the email address a magic link signs in to, without using up the link, so your app can ask the user to confirm it.

**Function Signature**

```swift theme={null}
public func getMagicLinkDetails(_ token: String) async throws -> MagicLinkDetails
```

A `PortalAuth` method and the first of the two steps that complete a magic link. A magic link signs in whoever opens it, to the account it was sent for, and anyone can request one for their own address and forward it to your user. Show the email this returns on your own confirmation screen, and call [`confirmMagicLink`](./portalauthconfirmmagiclink) only once the user confirms it is theirs. The SDK provides no UI for this.

**Parameters**

* **`token`**: The `token` of the `.magicLink` that [`parseRedirect`](./portalauthparseredirect) returned.

**Returns**

* **`MagicLinkDetails`**: Contains the following:
  * **`email`**: `String`, the full email address the link signs in to. It is never masked; masking it, if you want to, is up to your screen.

```swift theme={null}
public struct MagicLinkDetails: Hashable, Sendable {
    public let email: String
}
```

`MagicLinkDetails` redacts itself when printed: `"\(details)"`, `String(reflecting:)` and `dump` show `<redacted>` in place of the email. Read `email` to display it.

**Throws**

* `PortalAuthError.invalidArgument(name: "token")`: The token is empty or whitespace-only. Raised before any network call.
* `PortalAuthError.grantRejected`: Portal refused the link (a `401`): it has expired, was already used, or is otherwise unusable. Also raised without a request for a token that cannot be a Portal grant (characters outside the bearer-token alphabet). Not retryable: the user needs a new link — unless they already confirmed this link and are signed in, when there is nothing to do.
* `PortalAuthError.malformedResponse(path:missing:)`: The response carried no email.
* `PortalRequestsError.clientError`: A `429`. Each link can be looked up only a few times.
* Other transport errors unchanged.
* `CancellationError`: The calling task was already cancelled. Nothing is sent, so no lookup is spent.

**Notes**

* **Whatever it throws, do not confirm the link.** A link whose email the user has not seen must not be exchanged.
* Nothing is exchanged, persisted or remembered, and it does not wait for a confirmation in progress. The link stays usable until it expires, 15 minutes after it is sent.
* Call it once per confirmation screen and keep the result while the user decides, rather than looking the link up again. A spent or forged link is rejected with `.grantRejected` before the lookup limit applies.
* **A link that has already been confirmed is spent**, so this rejects it with `.grantRejected`; it never answers from memory. When iOS delivers a link again after the user confirmed it, send it straight to `confirmMagicLink`, which returns the remembered result. The SDK cannot tell that case apart from the token alone, so your app remembers which link the user confirmed — keep the `AuthRedirect.MagicLink`, which redacts the token when printed, rather than the bare string. That memory, like the SDK's, lasts only while the app runs: after a relaunch, restore the session with [`restoreSession`](./portalauthrestoresession) before routing redirects, and treat a `.grantRejected` for a link that arrives while the user is signed in as nothing to do.
* Portal does not require this lookup before the exchange, and the SDK does not enforce it. Call it first in any case: it also reports an expired or already used link before the user is asked to confirm.
* The email is personal data: show it, never log it.
* Available starting from SDK version 8.2.0.

**Example Usage**

```swift theme={null}
import PortalSwift

// Simplified. The Client Auth guide's version also looks each link up only once, even when
// iOS delivers it again while its confirmation is on screen.
@MainActor
func showMagicLinkConfirmation(for link: AuthRedirect.MagicLink) async {
    // Delivered again after the user confirmed it: the link is spent, so its details
    // can't be read; confirmMagicLink returns the remembered result instead.
    if link == confirmedLink {
        await confirmTapped(link: link)
        return
    }

    do {
        let details = try await auth.getMagicLinkDetails(link.token)
        // Your own screen. Confirm calls confirmTapped(link:), which calls confirmMagicLink.
        presentConfirmation(email: details.email, link: link)
    } catch PortalAuthError.grantRejected {
        // After a relaunch, this is also how a link the user already confirmed comes back.
        guard !isSignedIn() else { return }
        showSignInError("This sign-in link can no longer be used. Request a new one.")
    } catch {
        // Never confirm a link whose email could not be read, the lookup limit included.
        showSignInError("This sign-in link could not be checked. Request a new one.")
    }
}
```

**Related Documentation**

* [parseRedirect reference](https://docs.portalhq.io/sdks/ios/reference/portalauthparseredirect.md)
* [confirmMagicLink reference](https://docs.portalhq.io/sdks/ios/reference/portalauthconfirmmagiclink.md)
* [sendMagicLink reference](https://docs.portalhq.io/sdks/ios/reference/portalauthsendmagiclink.md)
* [Confirm a magic link](https://docs.portalhq.io/sdks/ios/guide/client-auth.md#confirm-a-magic-link)
* [Email magic links](https://docs.portalhq.io/resources/authentication/email-magic-links.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.