Home [React-Native] Firebase Storage ์‚ฌ์šฉ ์‹œ Possible Unhandled Priomise Rejection
Post
Cancel

[React-Native] Firebase Storage ์‚ฌ์šฉ ์‹œ Possible Unhandled Priomise Rejection

๐ŸšจWARN : Possible Unhandled Promise Rejection

Error: [storage/unauthorized] User is not authorized to perform the desired action.


๐Ÿ”ฅ์•„์นจ๋ถ€ํ„ฐ ๊ฐ€๋ณ๊ณ  ๊ท€์—ฌ์šด ์—๋Ÿฌ๋ฅผ ๋งˆ์ฃผ์ณค๋‹ค. ์‰ฝ๊ฒŒ ํ•ด๊ฒฐํ•ด์„œ ๊ธฐ๋ถ„์ด ์ข‹๋‹ค.


Firebase Storage๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ฒ˜์Œ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œ ํ•˜๋ ค๋Š”๋ฐ!
๊ฒฝ๊ณ ์™€ ํ•จ๊ป˜ ๋ฌดํ•œ ๋กœ๋”ฉ์ด ๋–ด๋‹ค.
WARN : Possible Unhandled Promise Rejection


๋ด๋„ ๋ฌด์Šจ ๊ฒฝ๊ณ ์ธ์ง€ ๋ชจ๋ฅด๊ฒ ๋˜ ๋‚˜๋Š” ์•„๋งˆ๋„ ์ •์ƒ. ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ๋ฅผ ํ•˜๋Š” ๋ถ€๋ถ„์—์„œ ์—๋Ÿฌ๋ฅผ ์ฒ˜๋ฆฌํ•ด์ฃผ์ง€ ์•Š์•„์„œ ๋ญ๊ฐ€ ๋ฌธ์ œ์ธ์ง€ ์—๋Ÿฌ๊ฐ€ ์•ˆ๋‚˜์˜ค๋Š”๊ฑฐ๋‹ค.

memoโ€ฆ async await๋กœ ๋น„๋™๊ธฐ์ฒ˜๋ฆฌ๋ฅผ ํ•œ ํ•จ์ˆ˜๋“ค์€ ๊ผญ ์—๋Ÿฌ์ฒ˜๋ฆฌ๋„ ์ž˜ ํ•ด์ฃผ์žโ€ฆโœ๏ธ

1
2
3
4
5
6
7
8
9
10
11
12
// try catch๋ฅผ ์ด์šฉํ•ด์„œ ์—๋Ÿฌ ๋ฐœ์ƒ์‹œ ์ฝ˜์†”์— ์ถœ๋ ฅํ•ด์ฃผ๊ธฐ.
try {
  if (Platform.OS === 'android') {
    await reference.putString(asset.base64, 'base64', {
      contentType: asset.type,
    });
  } else {
    await reference.putFile(asset.uri);
  }
} catch (err) {
  console.error(err);
}


๊ทธ๋Ÿฌ๋ฉด ์ด์ œ ์ง„์งœ ์—๋Ÿฌ๊ฐ€ ๋ชจ์Šต์„ ๋“œ๋Ÿฌ๋‚ธ๋‹ค.

Error: [storage/unauthorized] User is not authorized to perform the desired action.

์ด ์—๋Ÿฌ๋Š” Firebase Storage์˜ ๊ถŒํ•œ ์„ค์ • ๋ฌธ์ œ์ด๋‹ค.


Firebase ํ”„๋กœ์ ํŠธ ์ฝ˜์†” ์›นํŽ˜์ด์ง€์— ์ ‘์†ํ•ด์„œ ๋นŒ๋“œ > Storage ํŽ˜์ด์ง€์— ๊ฐ€๋ฉด, Rules ํƒญ์ด ์žˆ๋‹ค.
๊ฑฐ๊ธฐ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ๊ณ  ์“ฐ๋Š” ๊ถŒํ•œ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

1
2
3
4
5
6
7
8
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if false;
    }
  }
}

read, write ๊ถŒํ•œ์ด false๋กœ ๋˜์–ด์žˆ์–ด์„œ ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ๋‹ค.

1
2
3
4
5
6
7
8
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

์œ„์™€ ๊ฐ™์ด allow read, write ๋ผ๊ณ  ์ž‘์„ฑํ•˜๋ฉด ์ฝ๊ธฐ ์“ฐ๊ธฐ ๊ถŒํ•œ ๋ชจ๋‘ true๋กœ ํ—ˆ์šฉ๋œ๋‹ค. ์„ค์ •์„ ๋งˆ์น˜๊ณ  ์ ์šฉ๋˜๊ธฐ๋ฅผ ์ž ์‹œ ๊ธฐ๋‹ค๋ฆฌ๋ฉด ์ž˜ ์ž‘๋™ํ•œ๋‹ค!


๋ชจ๋‹์—๋Ÿฌ ํด๋ฆฌ์–ด๐Ÿ‘


โ€ฆ


๊ทธ๋ฆฌ๊ณ โ€ฆ 10๋ถ„ ๋’คโ€ฆ ์—ฌ์ „ํžˆ WARN : Possible Unhandled Promise Rejection ์—์„œ ๋„˜์–ด๊ฐ€์ง€๋ฅผ ์•Š๋Š” ๊ฒƒ์ด๋‹ค.


์ฝ˜์†” ๊ฐ’์„ ์ฐ์–ด๊ฐ€๋ฉฐ ์–ด๋””์„œ ๋ฉˆ์ถ”๋Š”์ง€ ์‚ดํŽด๋ณด๋‹ˆ,
usersCollection.doc(id).set({id, displayName, photoURL});
๋ฅผ ํ†ตํ•ด users ์ปฌ๋ ‰์…˜์— ๋ฌธ์„œ๋ฅผ ๋“ฑ๋กํ•˜๋Š” ๊ณผ์ •์—์„œ ๋ฉˆ์ถ˜๊ฒƒ์„ ํ™•์ธํ–ˆ๋‹ค.

๊ทธ๋ž˜์„œ ์ธ์ž ๊ฐ’์„ ์‚ดํŽด๋ณด๋‹ˆ displayName์ด undefined ์˜€๋‹ค.

์•ž์—์„œ ๋‹‰๋„ค์ž„ ์ž…๋ ฅ๋ฐ›๋Š” UI์™€ ๊ธฐ๋Šฅ ๋‹ค ๊ตฌํ˜„ํ•ด๋†“๊ณ ๋Š”, ํ…Œ์ŠคํŠธ ํ•  ๋•Œ ๋‹‰๋„ค์ž„ ์—†์ด ์‚ฌ์ง„๋งŒ ์ œ์ถœํ•ด์„œ ๊ทธ๋žฌ๋˜ ๊ฒƒ์ด์—ˆ๋‹ค.

ํ—ฟ๐Ÿ˜†

This post is licensed under CC BY 4.0 by the author.

[React-Native] Firebase ์•ฑ ์ถ”๊ฐ€ ๋””๋ฒ„๊ทธ ์„œ๋ช… ์ธ์ฆ์„œ SHA-1 (+ ์ž˜๋ชป๋œ ์˜ต์…˜ : .language=en)

[Git] Git Action & Git Branch Protection Rule ์„ ํ†ตํ•œ ํ˜‘์—… ์ฝ”๋“œ ๊ด€๋ฆฌ!