@carlomigueldy/atlantis-world-auth
v1.1.7
Published
Authentication module for authenticating to the game API.
Downloads
21
Readme
Atlantis World Auth
Authentication module for authenticating to the game API.
Getting Started
Install the package
yarn add @atlantis-world/auth --dev # or `npm i -D @atlantis-world/auth`Optional but recommended, install web3modal package
yarn add web3modal --dev # or `npm i -D web3modal`Import and use createAuthClient
import { createAuthClient } from "@atlantis-world/auth";
// Optional but recommended; You can use anything to grab web3 the provider
import Web3Modal from "web3modal";
async function example() {
const web3Modal = new Web3Modal({
network: "mainnet",
});
const provider = await web3Modal.connect();
const auth = createAuthClient(provider, {
apiBaseUrl: process.env.API_BASE_URL,
});
// Login
const authentiacteResult = await atlantisWorldAuth.authenticate();
/**
* {
* user: { ... },
* access_token: "...",
* token_type: "..."
* }
*/
console.log(authentiacteResult);
// Grab current authenticated user object
const currentUser = await atlantisWorldAuth.currentUser(authentiacteResult.access_token);
/**
* {
* _id: "...",
* address: "0x...",
* name: "...",
* created_at: "...",
* updated_at: "...",
* deleted_at: null,
* }
*/
console.log(currentUser);
}