createMagicURLToken method

Future<Token> createMagicURLToken({
  1. required String userId,
  2. required String email,
  3. String? url,
  4. bool? phrase,
})

Create magic URL token

Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the POST /v1/account/sessions/token endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default.

A user is limited to 10 active sessions at a time by default. Learn more about session limits.

Implementation

Future<models.Token> createMagicURLToken(
    {required String userId,
    required String email,
    String? url,
    bool? phrase}) async {
  const String apiPath = '/account/tokens/magic-url';

  final Map<String, dynamic> apiParams = {
    'userId': userId,
    'email': email,
    'url': url,
    'phrase': phrase,
  };

  final Map<String, String> apiHeaders = {
    'content-type': 'application/json',
  };

  final res = await client.call(HttpMethod.post,
      path: apiPath, params: apiParams, headers: apiHeaders);

  return models.Token.fromMap(res.data);
}