Wepin Login Library V1 from Web. This package is exclusively available for use in web environments.
⚠️ Notice:
This package is only available for web environments and cannot be used in Android or iOS hybrid apps (Webview).
If you are using this package in a Server Side Rendering (SSR) environment, make sure to load the package only on the Client Side Rendering (CSR) side.
Please refer to the following code for implementation:
const initWepinLogin = async () => {
const { WepinLogin } = await import('@wepin/login-js');
const wepinLogin = new WepinLogin({
appKey: '',
appId: '',
});
await wepinLogin.init();
}
After signing up for Wepin Workspace, go to the development tools menu and enter the information for each app platform to receive your App ID and App Key.
To install the Wepin Login Library, you can use npm, yarn, or a CDN: Using npm:
npm install @wepin/login-js
Using yarn:
yarn add @wepin/login-js
Using CDN: You can also include the library directly via CDN by adding the following script tag to your HTML file:
<script src="https://cdn.jsdelivr.net/npm/@wepin/login-js/dist/umd/wepin-login.umd.js"></script>
Using npm or yarn:
import { WepinLogin } from '@wepin/login-js'
Using CDN:
const { WepinLogin } = window.WepinLogin
const wepinLogin = new WepinLogin({
appId: 'wepinAppId',
appKey: 'wepinAppKey',
})
await wepinLogin.init(language?)
language <string> optional
'ko')
Currently, only 'ko', 'en' and 'ja' are supported.await wepinLogin.init('ko')
wepinLogin.isInitialized()
The isInitialized() method checks Wepin Login Library is initialized.
wepinLogin.changeLanguage(language)
language <string>
'ko', 'en' and 'ja' are supported.wepinLogin.changeLanguage('ko')
Methods can be used after initialization of Wepin Login Library.
await wepinLogin.loginWithOauthProvider(params)
A new window will open and proceed to log in to wepin firebase. Returns firebase login info upon successful login.
params <object>
provider <string> - Provider for Firebase login. The value must be one of the supported login provider names in lowercase, such as 'google', 'naver', 'discord', 'apple', 'facebook', or 'line'. Please refer to Wepin Social Login Auth Provider documentation to check the supported login providers.withLogout <boolean> optionalprovider <string>token <object>
idToken <string> - wepin firebase idTokenrefreshToken ```error <string> - error messageidToken <string> optional - id token valueaccessToken <string> optional - accessToken token valueprovider <string> optional - Provider that issued the access tokenInvalid provider: Incorrect value of provider parameterUser canceled : When the user closes the window during the login process.Internal error : In others error situations.const user = await wepinLogin.loginWithOauthProvider(true)
{
"provider": "google",
"token": {
"idToken": "ab2231df....ad0f3291",
"refreshToken": "eyJHGciO....adQssw5c",
}
}
{
"error": "required/register_email",
"provider": "naver",
"accessToken": "eyJHGciO....adQssw5c",
}
await wepinLogin.signUpWithEmailAndPassword(email, password, openWepinWallet?)
It signs up on the wepin firebase with your email and password. Returns firebase login info upon successful login.
email <string> - User emailpassword <string> - User passwordopenWepinWallet <boolean> - optional Whether to open the authentication email sending page of the Wepin Wallet.provider <'email'>token <object>
idToken <string> - wepin firebase idTokenrefreshToken ```auth/email-verified: An authentication email has been sent for registration, and email verification is required.auth/existed-email : The email is already registered.fail/send-email : Failed to send authentication email.fail/email-verified : Email verification failed.const user = await wepinLogin.signUpWithEmailAndPassword('abc@defg.com', 'abcdef123&')
{
"provider": "email",
"token": {
"idToken": "ab2231df....ad0f3291",
"refreshToken": "eyJHGciO....adQssw5c",
}
}
await wepinLogin.loginWithEmailAndPassword(email, password)
It logs in to the Wepin firebase with your email and password. Returns firebase login info upon successful login.
email <string> - User emailpassword <string> - User passwordprovider <'email'>token <object>
idToken <string> - wepin firebase idTokenrefreshToken ```const user = await wepinLogin.loginWithEmailAndPassword('abc@defg.com', 'abcdef123&')
{
"provider": "email",
"token": {
"idToken": "ab2231df....ad0f3291",
"refreshToken": "eyJHGciO....adQssw5c",
}
}
await wepinLogin.loginWithIdToken(params)
It logs in to the Wepin firebase with external id token. Returns firebase login info upon successful login.
params <object>
token <string> - id token value to be used for loginsign <string> - optional signature value for the token provided as the first parameter.(Signature Generation Methods)[!NOTE] Starting from @wepin/login-js version
0.0.29, the sign value is optional.If you choose to remove the authentication key issued from the Wepin Workspace, you may opt not to use the sign value.
(Wepin Workspace > Development Tools menu > Login tab > Auth Key > Delete)
The Auth Key menu is visible only if an authentication key was previously generated
provider <'external_token'>token <object>
idToken <string> - wepin firebase idTokenrefreshToken ```error <string> - error messageidToken <string> optional - id token valueconst user = await wepinLogin.loginWithIdToken({
token:'eyJHGciO....adQssw5c',
sign:'9753d4dc...c63466b9'
})
{
"provider": "external_token",
"token": {
"idToken": "ab2231df....ad0f3291",
"refreshToken": "eyJHGciO....adQssw5c",
}
}
{
"error": "required/register_email",
"idToken": "eyJHGciO....adQssw5c",
}
await wepinLogin.loginWithAccessToken(params)
It logs in to the Wepin firebase with external access token. Returns firebase login info upon successful login.
params <object>
provider <string> - Provider that issued the access token. The value must be one of the supported login provider names in lowercase, such as 'naver', 'discord', 'facebook'. Please refer to Wepin Simplified Login documentation to check the supported login providers.token <string> - access token value to be used for loginsign <string> - optional signature value for the token provided as the first parameter.(Signature Generation Methods)[!NOTE] Starting from @wepin/login-js version
0.0.29, the sign value is optional.If you choose to remove the authentication key issued from the Wepin Workspace, you may opt not to use the sign value.
(Wepin Workspace > Development Tools menu > Login tab > Auth Key > Delete)
The Auth Key menu is visible only if an authentication key was previously generated
provider <'external_token'>token <object>
idToken <string> - wepin firebase idTokenrefreshToken ```error <string> - error messageaccessToken <string> optional - accessToken token valueprovider <string> optional - Provider that issued the access tokenconst user = await wepinLogin.loginWithAccessToken({
provider: 'naver',
token:'eyJHGciO....adQssw5c',
sign:'9753d4dc...c63466b9'
})
{
"provider": "external_token",
"token": {
"idToken": "ab2231df....ad0f3291",
"refreshToken": "eyJHGciO....adQssw5c",
}
}
{
"error": "required/register_email",
"provider": "naver",
"accessToken": "eyJHGciO....adQssw5c",
}
await wepinLogin.sendVerifyEmail(params)
Method for registering an email and requesting email verification.
If a required/register_email error occurs, you need to register an email and request email verification.
Once email verification is complete, you should use the loginWithAccessToken or loginWithIdToken method to log in again with the AccessToken or IdToken used for the initial login.
params <ISendVerifyEmailParams>
email <string>provider <string> - Provider for Firebase login. The value must be one of the supported login provider names in lowercase, such as 'google', 'naver', 'discord', 'apple', 'facebook', or 'line'. Please refer to Wepin Social Login Auth Provider documentation to check the supported login providers.idToken <string> - id token value to be used for loginaccessToken <string> - access token value to be used for loginconst res = await wepinLogin.sendVerifyEmail({
email:'test@abcde.com'
provider: 'naver',
accessToken:'eyJHGciO....adQssw5c',
})
await wepinLogin.getRefreshFirebaseToken(prevFBToken?)
This method retrieves the current firebase token's information from the Wepin.
[!NOTE]
Starting from @wepin/login-js version
0.0.33, theprevFBTokenparameter has been added.
prevFBToken <LoginResult>optional (since v0.0.33)
provider <'email'|'apple'|'google'|'discord'|'naver'|'external_token'> - The login providertoken <object> - The login tokens from previous login
idToken <string> - wepin firebase idTokenrefreshToken <string> - wepin firebase refreshTokenprovider <'external_token'>token <object>
idToken <string> - wepin firebase idTokenrefreshToken ```// Without parameter (legacy way)
const result = await wepinLogin.getRefreshFirebaseToken()
// With prevFBToken parameter (since v0.0.33)
const prevToken = {
provider: 'google',
token: {
idToken: 'previous_id_token',
refreshToken: 'previous_refresh_token'
}
}
const result = await wepinLogin.getRefreshFirebaseToken(prevToken)
{
"provider": "external_token",
"token": {
"idToken": "ab2231df....ad0f3291",
"refreshToken": "eyJHGciO....adQssw5c",
}
}
Generates signatures to verify the issuer. It is mainly used to generate signatures for login-related information such as ID Tokens and Access Tokens.
import {getSignForLogin} from '@wepin/login-js'
const result = getSignForLogin(privKey, message);
privKey <string> - The authentication key used for signature generation.message <string> - The message or payload to be signed.‼️ Caution ‼️
The authentication key (
privKey) must be stored securely and must not be exposed to the outside. It is recommended to execute thegetSignForLogin()method on the backend rather than the frontend for enhanced security and protection of sensitive information.
const privKey = '0400112233445566778899001122334455667788990011223344556677889900'
const idToken = 'idtokenabcdef'
const sign = getSignForLogin(privKey, idToken)
const res = await wepinLogin.loginWithIdToken({
token: idToken,
sign
})
await wepinLogin.loginWepin({provider, token})
This method logs the user into the Wepin application using the specified provider and token.
The parameters should utilize the return values from the loginWithOauthProvider(), loginWithEmailAndPassword(), loginWithIdToken(), and loginWithAccessToken() methods within the this module.
provider <'google'|'apple'|'naver'|'discord'|'external_token'|'email'> - The login provider.token <{idToken: string; refreshToken: string}> - The login tokens.<boolean>const wepinLogin = WepinLogin({ appId: 'appId', appKey: 'appKey' })
const res = await wepinLogin.loginWithOauthProvider({ provider: 'google' })
const userInfo = await wepinLogin.loginWepin(res)
const userStatus = userInfo.userStatus
if(userStatus.loginStatus === 'pinRequired'||userStatus.loginStatus === 'registerRequired') {
// wepin register
}
{
"status": "success",
"userInfo": {
"userId": "120349034824234234",
"email": "abc@gmail.com",
"provider": "google",
"use2FA": true,
},
"walletId": "abcdsfsf123",
"userStatus": {
"loginRequired": "completed",
"pinRequired": false,
},
"token": {
"accessToken": "",
"refreshToken": "",
}
}
await wepinLogin.getCurrentWepinUser()
This method retrieves the current logged-in user's information from the Wepin.
<boolean>const userInfo = await wepinLogin.getCurrentWepinUser()
const userStatus = userInfo.userStatus
if(userStatus.loginStatus === 'pinRequired'||userStatus.loginStatus === 'registerRequired') {
// wepin register
}
{
"status": "success",
"userInfo": {
"userId": "120349034824234234",
"email": "abc@gmail.com",
"provider": "google",
"use2FA": true,
},
"walletId": "abcdsfsf123",
"userStatus": {
"loginRequired": "completed",
"pinRequired": false,
},
"token": {
"accessToken": "",
"refreshToken": "",
}
}
await wepinLogin.logout()
The logout() method logs out the user logged into Wepin.
Wepin login module Not initialized: If the Wepin login library is not initializedAlready logout : If the user is already logged outconst result = await wepinLogin.logout()
wepinLogin.finalize()
The finalize() method finalizes the Wepin Login Library.
wepinLogin.finalize()