Giter VIP home page Giter VIP logo

autivate_dart's Introduction

Authivate

style: very good analysis Powered by Mason License: MIT

The Dart SDK for the Authivate service

Authivate is a User Authentication and Management Platform

Installation ๐Ÿ’ป

โ— In order to start using Authivate you must have the Dart SDK installed on your machine.

Install via dart pub add:

dart pub add authivate

Example Usage

import 'dart:developer';

import 'package:authivate/authivate.dart';

void main() async {
  // initialize config
  final config = AuthivateConfig(
    apiKey: 'your-API-key-gotten-from-the-dashboard',
    projectId: 'authivate-test',
  );

  /// Initialize The Authivate Instance
  final autivateInstance = Authivate(config: config);

  /// Sign up a user
  await signUpUser();

  /// Sign In  a user
  await signInUser();

  /// Send a Confirm password email if the original one has expired
  await sendConfirmAccountEmail();

  /// Send a Forgot password email
  await sendForgotPasswordEmail();
}

Future<void> signUpUser() async {
  /// Sign Up a user
  const emailAddress = '[email protected]';
  const firstName = 'Peter';
  const lastName = 'Akande';
  const password = 'Password'; // Optional, Depending on Project Settings

  final signUpResponse = await Authivate.instance.signUpUser(
    emailAddress: emailAddress,
    lastName: lastName,
    firstName: firstName,
    password: password,
  );

  if (signUpResponse.isLeft()) {
    // An Error occurreed
    log(signUpResponse.failureMessage);
    return;
  }

  // The user was successfully signed up
  log(signUpResponse.successResponse.toString());

  ///Response
  ///{message: Email Sent!,
  /// user_record: {
  ///   email_address: [email protected],
  ///   is_verified: false,
  ///   date_created: 2023-11-11T11:12:48.293571Z,
  ///   first_name: Peter,
  ///   last_name: Akande,
  ///   user_unique_id: dp.ldcaopaggcapepaom
  ///   }
  /// }
}

Future<void> signInUser() async {
  /// Sign In a user
  const emailAddress = '[email protected]';
  const password = 'Password'; // Optional, Depending on Project Settings

  final signInResponse = await Authivate.instance.signInUser(
    emailAddress: emailAddress,
    password: password,
  );

  if (signInResponse.isLeft()) {
    // An Error occurreed
    log(signInResponse.failureMessage);
    return;
  }

  // The user was successfully signed in
  log(signInResponse.successResponse.toString());

  ///Response
  ///{
  /// user_record: {
  ///   email_address: [email protected],
  ///   is_verified: false,
  ///   date_created: 2023-11-11T11:12:48.293571Z,
  ///   first_name: Peter,
  ///   last_name: Akande,
  ///   user_unique_id: dp.ldcaopaggcapepaom
  ///   }
  /// }
}

Future<void> sendConfirmAccountEmail() async {
  /// Send a Confirm password email if the original one has expired
  const emailAddress = '[email protected]';

  final confirmAccountEmailResponse =
      await Authivate.instance.requestOTPForUser(
    emailAddress: emailAddress,
  );

  if (confirmAccountEmailResponse.isLeft()) {
    // An Error occurreed
    log(confirmAccountEmailResponse.failureMessage);
    return;
  }

  // Send a Confirm password email if the original one has expired
  log(confirmAccountEmailResponse.successResponse.toString());

  ///Response
  ///{{message: Email Sent Successfully}
}

Future<void> sendForgotPasswordEmail() async {
  /// Send a forgot password email
  const emailAddress = '[email protected]';

  final forgotPasswordResponse =
      await Authivate.instance.requestForgotPasswordForUser(
    emailAddress: emailAddress,
  );

  if (forgotPasswordResponse.isLeft()) {
    // An Error occurreed
    log(forgotPasswordResponse.failureMessage);
    return;
  }

  // Forgot password email sebt successfully
  log(forgotPasswordResponse.successResponse.toString());

  ///Response
  /// {message: Forgot Password Email Sent!}
}

autivate_dart's People

Contributors

peterakande avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.