# 메서드

## loginWithOauthProvider

```dart
await wepinLogin.loginWithOauthProvider(params);
```

인앱 브라우저가 열리고 OAuth 프로바이더에로그인합니다. Firebase 로그인 정보를 가져오려면 `loginWithIdToken()` 또는 `loginWithAccessToken()` 메서드를 호출해야 합니다.

#### **Parameters**

* **params** `<object>`
  * **provider** `<'google'|'naver'|'discord'|'apple'>`

    OAuth 로그인 프로바이더
  * **clientId** `<string>`

    OAuth 로그인 프로바이더의 클라이언트 ID

#### **Returns**

* **Promise\<LoginOauthResult>**
  * **provider** `<'google'|'naver'|'discord'|'apple'>`

    사용된 OAuth Provider의 이름
  * **token** `<string>`

    accessToken (Provider가 "naver" 또는 "discord"일 경우) 또는 idToken (Provider가 "google" 또는 "apple"일 경우)
  * **type** `<'id_token'|'access_token'>`

    OAuth 토큰의 유형

#### **Exception**

* [WepinLoginException](#wepinloginexception)

#### **Example**

```typescript
const user = await wepinLogin.loginWithOauthProvider({
  provider: "google",
  clientId: "your-google-client-id"
});
```

***

## signUpWithEmailAndPassword

```typescript
await wepinLogin.signUpWithEmailAndPassword(email, password, locale?)
```

이메일과 비밀번호로 Wepin Firebase에 회원가입을 합니다. 가입되지 않은 사용자의 경우 검증 이메일이 전송되며, `REQUIRED_EMAIL_VERIFIED` 오류가 발생합니다. 이미 가입된 사용자의 경우, `EXISTED_EMAIL` 오류가 발생하며 [loginWithEmailAndPassword](#loginwithemailandpassword)를 호출하여 로그인 프로세스를 진행합니다. 로그인에 성공하면 Firebase 로그인 정보를 반환합니다.

#### **Parameters**

* **email** `<string>`

  사용자 이메일
* **password** `<string>`

  사용자 비밀번호
* **locale** `<string>` ***optional***

  인증 이메일의 언어 설정 (기본 값: "en")

#### **Returns**

* **Promise\<LoginResult>**
  * **provider** `<string>`

    로그인에 사용된 프로바이더(이 경우, 'email')
  * **token** `<object>`
    * **idToken** `<string>`

      Wepin Firebase ID Token
    * **refreshToken** `<string>`

      Wepin Firebase refresh Token

#### **Exception**

* [WepinLoginException](#wepinloginexception)

#### **Example**

```typescript
const user = await wepinLogin.signUpWithEmailAndPassword(
  'abc@defg.com', 
  'abcdef123&'
);
```

***

## loginWithEmailAndPassword

```typescript
await wepinLogin.loginWithEmailAndPassword(email, password);
```

이메일과 비밀번호를 사용하여 Wepin Firebase에 로그인합니다. 로그인에 성공하면 Firebase 로그인 정보를 반환합니다.

#### **Parameters**

* **email** `<string>`\
  사용자 이메일
* **password** `<string>`\
  사용자 비밀번호

#### **Returns**

* **Promise\<LoginResult>**
  * **provider** `<'email'>`

    로그인에 사용된 Provider
  * **token** `<object>`
    * **idToken** `<string>`

      Wepin Firebase ID Token
    * **refreshToken** `<string>`

      Wepin Firebase refresh Token

#### **Exception**

* [WepinLoginException](#wepinloginexception)

#### **Example**

```typescript
const user = await wepinLogin.loginWithEmailAndPassword(
  'abc@defg.com', 
  'abcdef123&'
);
```

***

## loginWithIdToken

```typescript
await wepinLogin.loginWithIdToken(params);
```

외부 ID 토큰을 사용하여 Wepin Firebase에 로그인합니다. 로그인에 성공하면 Firebase 로그인 정보를 반환합니다.

#### **Parameters**

* **params**`<object>`
  * **idToken** `<string>`\
    로그인에 사용될 ID Token 값
  * **sign** `<string>` **optional**\
    ID 토큰의 서명 값 ([`getSignForLogin()`](#getsignforlogin)의 반환값)

{% hint style="warning" %}
&#x20;Note

WepinLogin 버전 1.0.0부터는 `sign` 값이 선택 사항입니다.

[Wepin Workspace](https://workspace.wepin.io/) 에서 발급된 인증 키를 제거하는 경우, `sign` 값을 사용하지 않아도 됩니다.

(Wepin Workspace > 개발 도구 메뉴 > 로그인 탭 > 인증 키 > 삭제)

> 인증 키 메뉴는 이전에 인증 키를 발급한 경우에만 표시됩니다.
> {% endhint %}

#### **Returns**

* **Promise\<LoginResult>**
  * **provider** `<'external_token'>` \
    로그인에 사용된 프로바이더
  * **token** `<object>`
    * **idToken** `<string>`

      Wepin Firebase ID Token
    * **refreshToken** `<string>`

      Wepin Firebase refresh Token

#### **Exception**

* [WepinLoginException](#wepinloginexception)

#### **Example**

```typescript
const user = await wepinLogin.loginWithIdToken({
    idToken:'eyJHGciO....adQssw5c', 
    sign:'9753d4dc...c63466b9'
});
```

***

## loginWithAccessToken

```typescript
await wepinLogin.loginWithAccessToken(params);
```

외부 Access Token을 사용하여 Wepin Firebase에 로그인합니다. 로그인에 성공하면 Firebase 로그인 정보를 반환합니다.

#### **Parameters**

* **params**`<object>`
  * **provider** `<"naver"|"discord">`

    Access Token을 발급한 프로바이더
  * **accessToken** `<string>`

    로그인에 사용될 Access Token 값
  * **sign** `<string>` **optional**

    Access Token의 서명 값 (returned value of `getSignForLogin()`)

{% hint style="warning" %}
&#x20;Note

WepinLogin 버전 1.0.0부터는 `sign` 값이 선택 사항입니다.

[Wepin Workspace](https://workspace.wepin.io/) 에서 발급된 인증 키를 제거하는 경우, `sign` 값을 사용하지 않아도 됩니다.

(Wepin Workspace > 개발 도구 메뉴 > 로그인 탭 > 인증 키 > 삭제)

> 인증 키 메뉴는 이전에 인증 키를 발급한 경우에만 표시됩니다.
> {% endhint %}

#### **Returns**

* **Promise\<LoginResult>**
  * **provider** `<string>`

    로그인에 사용된 프로바이더(in this case, 'external\_token')
  * **token** `<object>`
    * **idToken** `<string>`

      Wepin Firebase ID Token
    * **refreshToken** `<string>`

      Wepin Firebase refresh Token

#### **Exception**

* [WepinLoginException](#wepinloginexception)

#### **Example**

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

***

## getRefreshFirebaseToken

```typescript
await wepinLogin.getRefreshFirebaseToken();
```

현재 Wepin Firebase 토큰의 정보를 가져옵니다.

#### **Parameters**

* None

#### **Returns**

* **Promise\<LoginResult>**
  * **provider** `<string>`\
    로그인에 사용된 프로바이더
    * `<'google'|'apple'|'naver'|'discord'|'email'|'external_token'>`
  * **token** `<object>`
    * **idToken** `<string>`\
      Wepin Firebase ID Token
    * **refreshToken** `<string>`\
      Wepin Firebase refresh Token

#### **Exception**

* [WepinLoginException](#wepinloginexception)

#### **Example**

```typescript
const user = await wepinLogin.getRefreshFirebaseToken();
```

***

## loginWepin

```typescript
await wepinLogin.loginWepin({ provider, token });
```

Wepin Firebase Token을 사용하여 사용자를 위핀에 로그인합니다.

#### **Parameters**

* **params** `<LoginResult>`\
  [`loginWithEmailAndPassword()`](#loginwithemailandpassword), [`loginWithIdToken()`](#loginwithidtoken), or [`loginWithAccessToken()`](#loginwithaccesstoken)의 반환 값

#### **Returns**

* **Promise\<IWepinUser>**&#x20;
  * **status** `<'success'|'fail'>`

    로그인 상태
  * **userInfo** `<object>`***optional***  - 사용자의 정보
    * **userId** `<string>`

      사용자의 ID
    * **email** `<string>`

      사용자의 이메일
    * **provider** `<'google'|'apple'|'naver'|'discord'|'email'|'external_token'>`

      로그인 Provider
    * **use2FA** `<boolean>`

      사용자가 이중 인증을 사용하는지 여부
  * **walletId** `<string>`

    사용자의 지갑 ID
  * **userStatus** `<object>` -사용자의 위핀 로그인 상태
    * **loginStats** `<'complete' | 'pinRequired' | 'registerRequired'>`

      사용자의 `loginStatus` 값이 'complete'가 아닌 경우, 사용자는 위핀에 register해야 합니다.
    * **pinRequired** `<boolean>`***optional***&#x20;

      PIN이 필요한지 여부
  * **token** `<object>`

    사용자의 Wepin Token

    * **accessToken** `<string>`\
      Access Token
    * **refreshToken** `<string>`\
      Refresh Token

#### **Exception**

* [WepinLoginException](#wepinloginexception)

#### **Example**

```typescript
const wepinLogin = WepinLogin({ appId: 'appId', appKey: 'appKey' });
const res = await wepinLogin.loginWithOauthProvider({ 
  provider: 'google', 
  clientId: 'clientId'
});

const userInfo = await wepinLogin.loginWepin(res);
const userStatus = userInfo.userStatus;
if (
  userStatus.loginStatus === 'pinRequired' ||
  userStatus.loginStatus === 'registerRequired'
) {
  // wepin register
}
```

## getCurrentWepinUser

```typescript
await wepinLogin.getCurrentWepinUser();
```

위핀에 현재 로그인한 사용자의 정보를 가져옵니다.

#### **Parameters**

* None

#### **Returns**

* **Promise\<IWepinUser>**&#x20;
  * **status** `<'success'|'fail'>`

    로그인 상태
  * **userInfo** `<object>`***optional***  - 사용자의 정보
    * **userId** `<string>`

      사용자의 ID
    * **email** `<string>`

      사용자의 이메일
    * **provider** `<'google'|'apple'|'naver'|'discord'|'email'|'external_token'>`

      로그인 Provider
    * **use2FA** `<boolean>`

      사용자가 이중 인증을 사용하는지 여부
  * **walletId** `<string>`

    사용자의 지갑 ID
  * **userStatus** `<object>` -사용자의 위핀 로그인 상태
    * **loginStats** `<'complete' | 'pinRequired' | 'registerRequired'>`

      사용자의 `loginStatus` 값이 'complete'가 아닌 경우, 사용자는 위핀에 register해야 합니다.
    * **pinRequired** `<boolean>`***optional***&#x20;

      PIN이 필요한지 여부
  * **token** `<object>`

    사용자의 Wepin Token

    * **accessToken** `<string>`\
      Access Token
    * **refreshToken** `<string>`\
      Refresh Token

#### **Exception**

* [WepinLoginException](#wepinloginexception)

#### **Example**

```typescript
const userInfo = await wepinLogin.getCurrentWepinUser();
const userStatus = userInfo.userStatus;
if (
  userStatus.loginStatus === 'pinRequired' ||
  userStatus.loginStatus === 'registerRequired'
) {
  // wepin register
}
```

## logout

```typescript
await wepinLogin.logout();
```

위핀에 로그인한 사용자를 로그아웃합니다.

#### **Parameters**

* None

#### **Returns**

* **Promise\<boolean>**

#### **Exception**

* [WepinLoginException](#wepinloginexception)

#### **Example**

```typescript
const result = await wepinLogin.logout();
if (result) {
  // Successfully logged out
}
```

## getSignForLogin

발급자를 확인하기 위한 서명을 생성합니다. 주로 ID Token 및 Access Token과 같은 로그인 관련 정보를 위한 서명을 생성하는 데 사용됩니다.

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

#### **Parameters**

* **privateKey** `<string>`\
  서명 생성에 사용되는 인증 키
* **message** `<string>`\
  서명될 메시지 또는 페이로드

{% hint style="info" %}
서명에 사용할 키는 [위핀 워크스페이스](https://workspace.wepin.io/login)에서 발급 받을 수 있습니다. 개발 도구 메뉴에서 로그인 탭의 인증키 발급 받기를 클릭하여 인증키를 확인하세요.
{% endhint %}

#### **Returns**

* **\<string>** \
  생성된 서명

{% hint style="warning" %}
인증 키(**privateKey**)는 반드시 안전하게 보관되어야 하며, 외부에 노출되지 않도록 주의해야 합니다. 보안과 민감한 정보 보호를 위해 `getSignForLogin()` 메서드는 프론트엔드가 아닌 백엔드에서 실행하는 것이 권장됩니다. 서명 생성 방법에 대해서는 아래 문서를 참고하세요.

* [Signature Generation Methods](https://github.com/WepinWallet/wepin-web-sdk-v1/blob/main/packages/login/SignatureGenerationMethods.md)
  {% endhint %}

#### **Example**

```typescript
const sign = getSignForLogin(
    '0400112233445566778899001122334455667788990011223344556677889900',
    'idtokenabcdef'
);

const res = await wepinLogin.loginWithIdToken(
    'eyJHGciO....adQssw5c', 
    sign
);
```

## finalize

```typescript
await wepinLogin.finalize();
```

Wepin Login Library 를 종료합니다.

#### **Parameters**

* None

#### **Returns**

* **Promise\<void>**

#### **Example**

```typescript
await wepinLogin.finalize();
```

## WepinLoginException

<table><thead><tr><th width="297">Error Code</th><th>Error Message</th><th>Error Description</th></tr></thead><tbody><tr><td><code>INVALID_APP_KEY</code></td><td>"InvalidAppKey"</td><td>The Wepin app key is invalid.</td></tr><tr><td><code>INVALID_PARAMETER</code></td><td>"InvalidParameters"</td><td>One or more parameters provided are invalid or missing.</td></tr><tr><td><code>INVALID_LOGIN_PROVIDER</code></td><td>"InvalidLoginProvider"</td><td>The login provider specified is not supported or is invalid.</td></tr><tr><td><code>INVALID_TOKEN</code></td><td>"InvalidToken"</td><td>The token does not exist.</td></tr><tr><td><code>INVALID_LOGIN_SESSION</code></td><td>"InvalidLoginSession"</td><td>The login session information does not exist.</td></tr><tr><td><code>NOT_INITIALIZED_ERROR</code></td><td>"NotInitialized"</td><td>The WepinLoginLibrary has not been properly initialized.</td></tr><tr><td><code>ALREADY_INITIALIZED_ERROR</code></td><td>"AlreadyInitialized"</td><td>The WepinLoginLibrary is already initialized, so the logout operation cannot be performed again.</td></tr><tr><td><code>USER_CANCLED</code></td><td>"UserCancelled"</td><td>The user has cancelled the operation.</td></tr><tr><td><code>UNKNOWN_ERROR</code></td><td>"UnknownError"</td><td>An unknown error has occurred, and the cause is not identified.</td></tr><tr><td><code>NOT_CONNECTED_INTERNET</code></td><td>"NotConnectedInternet"</td><td>The system is unable to detect an active internet connection.</td></tr><tr><td><code>FAILED_LOGIN</code></td><td>"FailedLogin"</td><td>The login attempt has failed due to incorrect credentials or other issues.</td></tr><tr><td><code>ALREADY_LOGOUT</code></td><td>"AlreadyLogout"</td><td>The user is already logged out, so the logout operation cannot be performed again.</td></tr><tr><td><code>INVALID_EMAIL_DOMAIN</code></td><td>"InvalidEmailDomain"</td><td>The provided email address's domain is not allowed or recognized by the system.</td></tr><tr><td><code>FAILED_SEND_EMAIL</code></td><td>"FailedSendEmail"</td><td>The system encountered an error while sending an email. This is because the email address is invalid or we sent verification emails too often. Please change your email or try again after 1 minute.</td></tr><tr><td><code>REQUIRED_EMAIL_VERIFIED</code></td><td>"RequiredEmailVerified"</td><td>Email verification is required to proceed with the requested operation.</td></tr><tr><td><code>INCORRECT_EMAIL_FORM</code></td><td>"incorrectEmailForm"</td><td>The provided email address does not match the expected format.</td></tr><tr><td><code>INCORRECT_PASSWORD_FORM</code></td><td>"IncorrectPasswordForm"</td><td>The provided password does not meet the required format or criteria.</td></tr><tr><td><code>NOT_INITIALIZED_NETWORK</code></td><td>"NotInitializedNetwork"</td><td>The network or connection required for the operation has not been properly initialized.</td></tr><tr><td><code>REQUIRED_SIGNUP_EMAIL</code></td><td>"RequiredSignupEmail"</td><td>The user needs to sign up with an email address to proceed.</td></tr><tr><td><code>FAILED_EMAIL_VERIFIED</code></td><td>"FailedEmailVerified"</td><td>The WepinLoginLibrary encountered an issue while attempting to verify the provided email address.</td></tr><tr><td><code>FAILED_PASSWORD_SETTING</code></td><td>"failedPasswordSetting"</td><td>Failed to set the password. This could be due to issues with the provided password or internal errors during the password setting process.</td></tr><tr><td><code>EXISTED_EMAIL</code></td><td>"ExistedEmail"</td><td>The provided email address is already registered. This error occurs when attempting to sign up with an email that is already in use.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/widget-integration/react-native-sdk/login-library/methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
