Frontend ๊ฐœ๋ฐœ์ž - hyo.loui

Project : MZL - ๋กœ๊ทธ์ธ ๋ณธ๋ฌธ

Project

Project : MZL - ๋กœ๊ทธ์ธ

hyo.loui 2023. 1. 11. 00:24

๐ŸŽฏ๋ชฉ์  :

Firebase - Authentication : ๋กœ๊ทธ์ธ / ๋กœ๊ทธ์•„์›ƒ
๊ธฐ๋Šฅ ํ•™์Šต ๋ฐ ์ ์šฉ >> Firebase : FireStore ์—ฐ๊ฒฐ

 

๐Ÿคข ์˜ค๋ฅ˜ ๋ฐœ๊ฒฌ (๋ฏธํ•ด๊ฒฐ

  • ๋กœ๊ทธ์•„์›ƒ ํ›„ currentUser๊ฐ€ null์ด ๋˜์–ด ๋งˆ์ดํŽ˜์ด์ง€ tabs ํด๋ฆญ์‹œ ์—๋Ÿฌ๊ฐ€ ์ถœ๋ ฅ

 


1. UI Layout ๋งŒ๋“ค๊ธฐ

 ํšŒ์›๊ฐ€์ž… UI์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ <KeyboardAwareScrollView/> ๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค..

 

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๊ฐ€์ ธ์˜จ ํƒœ๊ทธ๋กœ ์ƒ์œ„๋ฅผ ๊ฐ์‹ธ์ฃผ์—ˆ๊ณ ,

 

ID(์•„์ด๋””), Password(๋น„๋ฐ€๋ฒˆํ˜ธ), Login(๋กœ๊ทธ์ธ), Register(ํšŒ์›๊ฐ€์ž…)
๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋ˆ„์—ˆ๋‹ค

 

์Šคํƒ€์ผ์€ Emotion์„ ์‚ฌ์šฉํ–ˆ๋‹ค

 

ํšŒ์›๊ฐ€์ž…๊ธฐ๋Šฅ, ๋กœ๊ทธ์ธ ์‹คํ–‰ ํ•จ์ˆ˜์—์„œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ฐ€ ์ง„ํ–‰๋˜๋Š”๋ฐ

ํ•ด๋‹น ๋ถ€๋ถ„์˜ ๋กœ์ง์ด ์ „์ฒด์ ์œผ๋กœ ์ฝ”๋“œ๊ฐ€ ๊ธธ๊ณ  ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ ธ

 

์œ ํšจ์„ฑ๊ฒ€์‚ฌ๋ฅผ ํ•˜๋Š” ๋ถ€๋ถ„์„ ๋”ฐ๋กœ ๋‚˜๋ˆ„์–ด ๋ฆฌํŽ™ํ† ๋ง ํ•ด ์ฃผ์—ˆ๋‹ค

 


2. ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

์œ„ ์ฝ”๋“œ์—์„œ๋„ ํšŒ์›๊ฐ€์ž…๊ณผ ๊ฐ™์ด

 

์œ ํšจ์„ฑ๊ฒ€์‚ฌ๋ฅผ ํ†ต๊ณผํ•˜์ง€ ๋ชปํ–ˆ์„ ๋•Œ alertTextTimer ๋ผ๋Š” ํ•จ์ˆ˜๋กœ

UI๋ถ€๋ถ„์— ์‚ฝ์ž…ํ•ด ๋ฌธ์ œ ๋ถ€๋ถ„์„ ํ…์ŠคํŠธ๋กœ ๋ณด์—ฌ์ฃผ๊ณ ,

useRef๋ฅผ ํ™œ์šฉํ•ด ํ•ด๋‹นํ•˜๋Š” ์˜์—ญ(TextInput)์ด focus๊ฐ€ ๋˜๋„๋ก ๋งŒ๋“ค์–ด์ฃผ์—ˆ๋‹ค

focus == ๋งˆ์šฐ์Šค๋กœ ํด๋ฆญํ•˜์—ฌ ์ž…๋ ฅ์ƒํƒœ๋กœ ๋งŒ๋“ ๊ฒƒ!


3. authentication >> ๋กœ๊ทธ์ธ api

์ฒซ๋ฒˆ์งธ๋กœ ์œ ํšจ์„ฑ๊ฒ€์‚ฌ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•ด ์กฐ๊ฑด๊ณผ ์ผ์น˜ํ•˜์—ฌ

๊ฒ€์‚ฌ์— ๊ฑธ๋ฆฐ๋‹ค๋ฉด ๊ทธ๋Œ€๋กœ return ๋˜์–ด ๋‹ค๋ฅธ ์ฝ”๋“œ ์‹คํ–‰์—†์ด ์ข…๋ฃŒ๋œ๋‹ค

 

signInWithEmailAndPassword API๋ฅผ importํ•˜์—ฌ

ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์ธ์ž๋กœ 

  - auth(firebase authentication)

  - email (TextInput์—์„œ setSateํ•˜์—ฌ ์ž…๋ ฅ๋ฐ›์€ state๊ฐ’)

  - pasword (TextInput์—์„œ setSateํ•˜์—ฌ ์ž…๋ ฅ๋ฐ›์€ state๊ฐ’)

๋ฅผ ๋„˜๊ฒจ์ค€๋‹ค!

 

.then .catch ๋ฌธ์„ ํ™œ์šฉํ•ด 

 

์‹คํ–‰์ด ๋œ๋‹ค๋ฉด ์•Œ๋Ÿฟ(์•Œ๋ฆผ์ฐฝ)์œผ๋กœ ์•Œ๋ ค์ฃผ๊ณ ,

ํ™•์ธ( OK ) ๋ฒ„ํŠผ์„ (onPress())๋ˆ„๋ฅด๋ฉด reset ํ•จ์ˆ˜๋กœ

ํ™ˆํ™”๋ฉด์œผ๋กœ ์ด๋™๋˜๊ฒŒ ํ•˜๊ณ ,

 

์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๊ฒƒ์„ catch๋ฌธ์œผ๋กœ ์žก์•„

์ฝ˜์†”์— ์—๋Ÿฌ๋ฉ”์„ธ์ง€๋ฅผ ๋„์›Œ ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ์— ๋Œ€ํ•ด

firebase๊ฐ€ ๋‚ด๋ ค์ฃผ๋Š” ํ…์ŠคํŠธ๋ฅผ ์กฐ๊ฑด๋ฌธ์œผ๋กœ ๊ฒ€์‚ฌํ•˜๊ณ , include๋ฅผ ํ†ตํ•ด 

์œ ํšจ์„ฑ๊ฒ€์‚ฌ์™€ ๊ฐ™์€ ํšจ๊ณผ์ฒ˜๋Ÿผ ์œ ์ €์— ์นœํ™”์ ์ธ text๋ฅผ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ์—ˆ๋‹ค

 


+ ์˜ค๋ฅ˜ ๋ฐœ๊ฒฌ :

// ๋งˆ์ดํŽ˜์ด์ง€ screen

๋กœ๊ทธ์•„์›ƒ ๊ธฐ๋Šฅ ๊ตฌํ˜„์ค‘ ๋กœ๊ทธ์•„์›ƒ์ด ๋˜์–ด

auth.currentUser๊ฐ€ ๊ฐ์ง€๋˜์ง€ ์•Š์œผ๋ฉด, ๋งˆ์ดํŽ˜์ด์ง€ ํด๋ฆญํ–ˆ์„ ๋•Œ

๋กœ๊ทธ์ธํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๋Š” ๊ฒƒ์„ ๊ตฌํ˜„ํ•˜๊ณ  ์žˆ์—ˆ๋‹ค.

 

ํ•˜์ง€๋งŒ ๋กœ๊ทธ์•„์›ƒ์ด ๋˜๋ฉด

currentUser๊ฐ€ null์ด ๋˜์–ด ๋งˆ์ดํŽ˜์ด์ง€ tabs ํด๋ฆญ์‹œ

์—๋Ÿฌ๊ฐ€ ์ถœ๋ ฅ๋˜์—ˆ๋‹ค.

 

ํ•ด๋‹น ์—๋Ÿฌ๋Š” ๋‚ด์ผ ํ•ด๊ฒฐํ•˜๊ณ  ์ž์„ธํžˆ ๋‹ค๋ฃจ๋„๋ก ํ•˜๊ฒ ๋‹ค!


 

 ์ตœ์ข… ์ •๋ฆฌ 

  1. ๋กœ์ง์€ ํšŒ์›๊ฐ€์ž…๊ณผ ๋งค์šฐ ์œ ์‚ฌ
  2. ์œ ํšจ์„ฑ๊ฒ€์‚ฌ ํ•จ์ˆ˜ ๋ถ„๋ฆฌํ•˜์—ฌ ์ฝ”๋“œ ๊ฐ„์†Œํ™” ์ง„ํ–‰!
  3. ๋กœ๊ทธ์ธ์ด ์™„๋ฃŒ๋˜๋ฉด alert์œผ๋กœ ์•Œ๋ ค์ฃผ๊ณ , navigate ๊ธฐ๋Šฅ์ธ reset์„ ํ™œ์šฉํ•˜์—ฌ Homeํ™”๋ฉด์œผ๋กœ ์ด๋™
  4. KeyboardAwareScrollView ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ : ํ•˜๋‹จ ๋งํฌ ์ฐธ์กฐ

https://github.com/APSL/react-native-keyboard-aware-scroll-view

 

GitHub - APSL/react-native-keyboard-aware-scroll-view: A ScrollView component that handles keyboard appearance and automatically

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput. - GitHub - APSL/react-native-keyboard-aware-scroll-view: A ScrollView component that handles ...

github.com