Arcana SDK to perform logins on your app.
npm install --save @arcana/auth
yarn add @arcana/auth
<script src="https://cdn.jsdelivr.net/npm/@arcana/auth"></script>
<script src="https://unpkg.com/@arcana/auth"></script>
const { AuthProvider, SocialLoginType } = window.arcana.auth;
// or
import { AuthProvider,SocialLoginType } from '@arcana/auth';
const auth = await AuthProvider.init({
appID: `${appID}`,
flow: 'redirect', // 'popup' or 'redirect'
redirectUri:'' // Can be ignored for redirect flow if same as login page
});
await auth.loginWithSocial(SocialLoginType.google);
const userInfo = auth.getUserInfo();
/*
UserInfo: {
loginType: 'google',
userInfo: {
id: '[email protected]',
name: 'ABC DEF',
email: '',
picture: ''
},
privateKey: ''
}
*/
const { X, Y } = await auth.getPublicKey({
verifier: <loginType>,
id: <email | username>,
});
const loggedIn = auth.isLoggedIn();
if (!loggedIn) {
await auth.loginWithSocial(SocialLoginType.google);
}
const userInfo = auth.getUserInfo()
await auth.logout();
login.js
window.onload = async () => {
const auth = await AuthProvider.init({
appID: `${appID}`,
flow: 'redirect',
redirectUri:'path/to/redirect'
});
googleLoginBtn.addEventListener('click', async () => {
await auth.loginWithSocial(SocialLoginType.google);
});
}
- Skip
redirectUri
in params if the it is same as login page.
login.js
window.onload = async () => {
const auth = await AuthProvider.init({
appID: `${appID}`,
redirectUri:'path/to/redirect'
});
googleLoginBtn.addEventListener('click', async () => {
await auth.loginWithSocial(SocialLoginType.google);
if(auth.isLoggedIn()) {
const info = auth.getUserInfo();
// Store info and redirect accordingly
}
});
}
redirect.js
window.onload = async () => {
AuthProvider.handleRedirectPage(<origin>);
};
SocialLoginType
- discord, twitter, github, google, twitch, redditorigin
- Base url of your app.