> For the complete documentation index, see [llms.txt](https://shhn0509.gitbook.io/react/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shhn0509.gitbook.io/react/firebase/auth.md).

# 인증

## 1. 인증 시작하기  <a href="#start" id="start"></a>

firebase의 인증을 시작하려면 모듈을 불러와야 한다. &#x20;

```javascript
import firebase from "firebase/app";
import "firebase/auth";
```

## 2. 메서드 사용 <a href="#method" id="method"></a>

인증으로 이메일 또는 비밀번호를 firebase에 등록하거나 해당 사용자를 확인 하기 위해서 사용하는 메서드가 있다.&#x20;

* firebase.auth().**createUserWithEmailAndPassword**(email, password) → 등록&#x20;
* firebase.auth()**.signInWithEmailAndPassword**(email, password) → 인증&#x20;

```javascript
// Firebase 인증 객체 
const auth = firebase.auth()

function signInWithEmailPassword() {
  var email = "test@example.com";
  var password = "hunter2";
  // [START auth_signin_password]
  auth.signInWithEmailAndPassword(email, password)
    .then((user) => {
      // Signed in 
      // ...
    })
    .catch((error) => {
      var errorCode = error.code;
      var errorMessage = error.message;
    });
  // [END auth_signin_password]
}

function signUpWithEmailPasswoerd() {
  var email = "test@example.com";
  var password = "hunter2";
  // [START auth_signup_password]
  auth.createUserWithEmailAndPassword(email, password)
    .then((user) => {
      // Signed in 
      // ...
    })
    .catch((error) => {
      var errorCode = error.code;
      var errorMessage = error.message;
      // ..
    });
  // [END auth_signup_password]
}
```

## 참고  <a href="#reference" id="reference"></a>

* [Firebase 인증 시작하기 ](https://firebase.google.com/docs/auth/web/start)
* [auth 메서드 예시 코드 ](https://github.com/firebase/snippets-web/blob/94f5dc85944d0f84530c59e8442dfeddc1170872/auth/email.js#L27-L36)

{% embed url="<https://shhn0509.gitbook.io/react/react-study/react-router/practice/firebase>" %}
