Methods

Methods can be used after initializing the Wepin Login Library.

loginWithOauthProvider

await wepinLogin.loginWithOauthProvider(params)

Logs in to Wepin Firebase in a new window. Returns Firebase login information upon successful login.

If an error of required/register_email occurs, you will need to call the sendVerifyEmail method.

Parameters

  • params <object>

    • provider <'google'|'naver'|'discord'|'apple'|'line'|'facebook'> - Provider for Firebase login

    • withLogout <boolean> optional

      • true : Does not log out if already logged in.

      • false : Logs out and logs in again if already logged in.

Return value

  • Promise <LoginResult| LoginErrorResult>

    • <LoginResult>

      • provider <'google'|'naver'|'discord'|'apple'|'line'|'facebook'>

      • token <object>

        • idToken <string> wepin firebase idToken

        • refreshToken wepin firebase refreshToken

    • <LoginErrorResult>

      • error <string> error message

      • idToken <string> optional id token value

      • accessToken <string> optional accessToken token value

      • provider <'google'|'naver'|'discord'|'apple'|'line'|'facebook'> optional Provider that issued the access token

Exception

  • Invalid provider: If the provider parameter is incorrect

  • User canceled : If the user closes the window during login

  • Internal error : For other exceptions

Example

const user = await wepinLogin.loginWithOauthProvider(true)
  • response

    • LoginResult

      {
        "provider": "google",
        "token": {
            "idToken": "ab2231df....ad0f3291",
            "refreshToken": "eyJHGciO....adQssw5c",
        }
      }
    • LoginErrorResult

      {
        "error": "required/register_email",
        "provider": "naver",
        "accessToken": "eyJHGciO....adQssw5c",
      }

signUpWithEmailAndPassWord

await wepinLogin.signUpWithEmailAndPassword(email, password, openWepinWallet?)

Sign up for Wepin Firebase with an email and password. For users who have not yet registered, a verification email will be sent, and an auth/email-verified error will occur if verification is required. If the user is already registered, an auth/existed-email error will occur, and you should proceed with the login process by calling loginWithEmailAndPassword. Upon successful login, Firebase login information is returned.

Parameters

  • email <string> User email address

  • password <string>

    User email password

  • openWepinWallet <boolean> optional Whether to show the Wepin Wallet authentication email page

Return Value

  • Promise<LoginResult>

    • provider <'email'>

    • token <object>

      • idToken <string> wepin firebase idToken

      • refreshToken wepin firebase refreshToken

Exception

  • auth/email-verified: A verification email has been sent, email verification is required

  • auth/existed-email : The email is already registered

  • fail/send-email : Failed to send verification email

  • fail/email-verified : Email verification failed

Example

const user = await wepinLogin.signUpWithEmailAndPassword('abc@defg.com', 'abcdef123&')
  • response

    {
        "provider": "email",
        "token": {
            "idToken": "ab2231df....ad0f3291",
            "refreshToken": "eyJHGciO....adQssw5c",
        }
    }

loginWithEmailAndPassWord

await wepinLogin.loginWithEmailAndPassword(email, password)

Logs in to Wepin Firebase using email and password. Returns Firebase login information upon successful login.

Parameters

  • email <string> User email address

  • password <string>

    User email password

Return Value

  • Promise<LoginResult>

    • provider <'email'>

    • token <object>

      • idToken <string> wepin firebase idToken

      • refreshToken wepin firebase refreshToken

Example

const user = await wepinLogin.loginWithEmailAndPassword('abc@defg.com', 'abcdef123&')
  • response

    {
        "provider": "email",
        "token": {
            "idToken": "ab2231df....ad0f3291",
            "refreshToken": "eyJHGciO....adQssw5c",
        }
    }

loginWithIdToken

await wepinLogin.loginWithIdToken(params)

Logs in to Wepin Firebase using an external IdToken. Returns Firebase login information upon successful login.

If an error of required/register_email occurs, you will need to call the sendVerifyEmail method.

Parameters

  • params <object>

    • token <string> External IdToken used for login

    • sign <string>

      Signature of the token provided as the first parameter (Signature Generation Methods)

      Starting from @wepin/login-js version 0.0.29, the signvalue is optional. If you choose to remove the authentication key issued from the Wepin Workspace, you may opt not to use the signvalue. (Wepin Workspace > Development Tools menu > Login tab > Auth Key > Delete)

      The Auth Key menu is visible only if an authentication key was previously generated.

Return Value

  • Promise<LoginResult | LoginErrorResult>

    • <LoginResult>

      • provider <'external_token'>

        • token <object>

          • idToken <string> wepin firebase idToken

          • refreshToken wepin firebase refreshToken

    • <LoginErrorResult>

      • error <string> error message

        • idToken <string> optional id token value

Example

const user = await wepinLogin.loginWithIdToken({
    token:'eyJHGciO....adQssw5c', 
    sign:'9753d4dc...c63466b9'
})
  • response

    • LoginResult

      {
        "provider": "external_token",
        "token": {
            "idToken": "ab2231df....ad0f3291",
            "refreshToken": "eyJHGciO....adQssw5c",
        }
      }
    • LoginErrorResult

      {
        "error": "required/register_email",
        "idToken": "eyJHGciO....adQssw5c",
      }

loginWithAccessToken

await wepinLogin.loginWithAccessToken(params)

Logs in to Wepin Firebase using an external Access Token. Returns Firebase login information upon successful login.

If an error of required/register_email occurs, you will need to call the sendVerifyEmail method.

Parameters

  • params <object>

    • provider <'naver'|'discord'|'facebook'> Login provider from which the Access Token was issued

    • token <string> External Access Token used for login

    • sign <string>

      Signature of the token provided as the second parameter (Signature Generation Methods)

      Starting from @wepin/login-js version 0.0.29, the signvalue is optional. If you choose to remove the authentication key issued from the Wepin Workspace, you may opt not to use the signvalue. (Wepin Workspace > Development Tools menu > Login tab > Auth Key > Delete)

      The Auth Key menu is visible only if an authentication key was previously generated.

Return Value

  • Promise<LoginResult | LoginErrorResult>

    • <LoginResult>

      • provider <'external_token'>

        • token <object>

          • idToken <string> wepin firebase idToken

          • refreshToken wepin firebase refreshToken

    • <LoginErrorResult>

      • error <string> error message

      • accessToken <string> optional accessToken token value

      • provider <string> optional Provider that issued the access token

Example

const user = await wepinLogin.loginWithAccessToken({
    provider: 'naver', 
    token:'eyJHGciO....adQssw5c', 
    sign:'9753d4dc...c63466b9'
})
  • response

    • LoginResult

      {
        "provider": "external_token",
        "token": {
            "idToken": "ab2231df....ad0f3291",
            "refreshToken": "eyJHGciO....adQssw5c",
        }
      }
    • LoginErrorResult

      {
        "error": "required/register_email",
        "provider": "naver",
        "accessToken": "eyJHGciO....adQssw5c",
      }

getSignForLogin

import {getSignForLogin} from '@wepin/login-js'
const result = getSignForLogin(privKey, message);

It generates a signature to verify the issuer. Mainly used to generate signatures for login-related information such as IdToken and Access Token.

Parameters

  • privKey <string> Authentication key used to generate the signature

  • message <string> Message or payload to be signed

The key for signing can be obtained from Wepin Workspace. In the Development Tools menu, click Get your authentication key on the Login tab to retrieve the authentication key.

Return Value

  • <string>

    Signature value

The authentication key (privKey) should be stored securely and not exposed externally. To enhance security and protection of sensitive information, it is recommended to execute the getSignForLogin() method on the backend rather than the frontend.

Example

const privKey = '0400112233445566778899001122334455667788990011223344556677889900'
const idToken = 'idtokenabcdef'
const sign = getSignForLogin(privKey, idToken)

const res = await wepinLogin.loginWithIdToken({
    token: idToken, 
    sign
})

sendVerifyEmail

await wepinLogin.sendVerifyEmail(params)

The sendVerifyEmail method allows you to register an email and request email verification. If an error of required/register_email occurs, you must register the email and request verification. Once verification is completed, use the loginWithAccessToken or loginWithIdToken method to log in again with the previously used AccessToken or IdToken.

Supported Version

  • Supported in version 0.0.18 and later

Parameters

  • params <ISendVerifyEmailParams>

    • email <string> The email address to be registered and verified

    • provider <string> The login provider for Firebase. It must be one of the supported providers in lowercase, such as ‘google’, ‘naver’, ‘discord’, ‘apple’, ‘facebook’, or ‘line’. Refer to Wepin Social Login Auth Provider documentation for the full list of supported providers.

    • idToken <string> The id token to be used for login

    • accessToken <string> The access token to be used for login

Return Value

  • Promise<boolean>

Example

const res = await wepinLogin.sendVerifyEmail({
    email:'test@abcde.com'
    provider: 'naver', 
    accessToken:'eyJHGciO....adQssw5c', 
})

loginWepin

await wepinLogin.loginWepin({provider, token})

It logs the user into Wepin using the specified Login Provider and Token.

Parameters

The parameters for this method should utilize the return values from the loginWithOauthProvider(), loginWithEmailAndPassword(), loginWithIdToken(), and loginWithAccessToken() methods within this module.

  • provider <'google'|'apple'|'naver'|'discord'|'external_token'|'email'> Login Provider

  • token <object>

    • idToken <string> wepin firebase idToken

    • refreshToken wepin firebase refreshToken

Return Value

  • Promise<IWepinUser>

    • status <'success'|'fail'> Login result

    • userInfo <object> optional Information of the logged-in user

      • userId <string> User's Wepin ID

      • email <string> User's email address

      • provider<'google'|'apple'|'naver'|'discord'|'email'|'external_token'> Logged-in Provider

      • use2FA <boolean> Whether 2FA is enabled for the user

    • userStatus <object> Status information of the logged-in user

      • loginStats: <'complete' | 'pinRequired' | 'registerRequired'> If not 'complete', registration with Wepin is required

      • pinRequired <boolean> optional Whether the user's PIN number is required

    • token <object> User's wepin firebase token

      • idToken <string> wepin firebase idToken

      • refreshToken wepin firebase refreshToken

Example

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
}
  • response

{
    "status": "success",
    "userInfo": {
      "userId": "120349034824234234",
      "email": "abc@gmail.com",
      "provider": "google",
      "use2FA": true,
    },
    "walletId": "abcdsfsf123",
    "userStatus": {
        "loginRequired": "completed",
        "pinRequired": false,
    },
    "token": {
        "accessToken": "",
        "refreshToken": "",
    }
}

logout

await wepinLogin.logout()

It logs out the Wepin user.

Parameters

  • <void>

Return Value

  • Promise <boolean>

    true if successful

Exception

  • Wepin login module Not initialized: If the Wepin Login Library has not been initialized

  • Already logout : If the user is already logged out

Example

const result = await wepinLogin.logout()

finalize

wepinLogin.finalize()

It terminates the use of the Wepin Login Library.

Parameters

  • <void>

Return Value

  • <void>

Example

wepinLogin.finalize()

Last updated