takyon-auth
v1.1.0
Published
This is an npm package which provides a convenient way to interact with the Takyon Auth API. It allows easy fetching of user details from Bearer Token or API Key.
Downloads
8
Readme
Takyon Auth npm Package
This is an npm package which provides a convenient way to interact with the Takyon Auth API. It allows easy fetching of user details from Bearer Token or API Key.
Installation
Use the package manager npm to install this package.
npm install takyon-auth
Usage
Import the package into your project and use the following functions:
getTakyonUserFromBearerTokenOrFail(token:string)
: To get user details from Bearer Token.
import { getTakyonUserFromBearerTokenOrFail } from 'takyon-auth';
getTakyonUserFromBearerTokenOrFail('your_bearer_token')
.then(userDetails => console.log(userDetails))
.catch(error => console.error(error));
getTakyonUserFromApiKeyOrFail(token:string)
: To get user details from API Key.
import { getTakyonUserFromApiKeyOrFail } from 'takyon-auth';
getTakyonUserFromApiKeyOrFail('your_api_key')
.then(userDetails => console.log(userDetails))
.catch(error => console.error(error));
User Interface
The returned user details conform to the User interface.
interface User {
isAdmin?: boolean;
email: string;
password?: string;
emailVerified?: boolean;
phone?: string;
phonePrefix?: string;
firstName?: string;
secondName?: string;
wallet?: Array<string>;
stripeId?: string;
stripeChargesEnabled?: boolean;
stripeDetailsSubmitted?: boolean;
stripePayoutsEnabled?: boolean;
lang?: string;
marketingEmails?: boolean;
platformPolicy?: boolean;
image?: string;
connections?: { ip: string; userAgent?: string; firstSeen: Date }[];
}
Error Handling
If the request fails, the functions will throw an error with the response error message.
try {
const userDetails = await getTakyonUserFromBearerTokenOrFail('your_bearer_token');
} catch (error) {
console.error(error);
}
License
This package is licensed under the MIT license.