flutter/기타

Firebase로 회원 생성 / 로그인

coens 2022. 5. 19. 11:01

Firebase로 회원을 생성하고 로그인 하고, 다른 페이지에 currentUser로 해당 사용자의 정보를 쓸수 있다.

최소한의 예제이니 그냥 main함수에 때려넣음;;; 

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  final _authentification = FirebaseAuth.instance;

  String userEmail = "test@email.com";
  String userPassword = "12345678";

  // 새로운 사용자 생성
  //final UserCredential newUser = await _authentification.createUserWithEmailAndPassword(email: userEmail, password: userPassword);

  //로그인
  final UserCredential user = await _authentification.signInWithEmailAndPassword(email: userEmail, password: userPassword);

  // 현재 사용자
  print(_authentification.currentUser);
}

 

파이어베이스 콘솔에서 확인하자.