firebase-tools : 7.0.2
ํ๋ซํผ : Oracle Linux Server 7.6, Node 10.15
"firebase-admin": "^ 8.2.0", "firebase-functions": "^ 3.0.2"๋ฅผ ์ฌ์ฉํ์ฌ https ํจ์๋ฅผ ์๋ฎฌ๋ ์ดํธํฉ๋๋ค.
firebase ํจ์๋ก ๋ชจ๋ https ํจ์๋ฅผ ์คํํฉ๋๋ค
์ค๋ฅ ์์ (firebase-tools 7.0.0์ ์ค๋ฅ ์์)
๊ธฐ๋ฅ ์์ฒญ์ ๋ณด๋์ต๋๋ค.
firebase > โ Error: The incoming JSON object does not contain a client_email field
at JWT.fromJSON (/riderequest/functions/node_modules/google-auth-library/build/src/auth/jwtclient.js:165:19)
at GoogleAuth.fromJSON (/riderequest/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:294:16)
at GoogleAuth.getClient (/riderequest/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:476:52)
at GrpcClient._getCredentials (/riderequest/functions/node_modules/google-gax/build/src/grpc.js:107:40)
at GrpcClient.createStub (/riderequest/functions/node_modules/google-gax/build/src/grpc.js:223:34)
at new FirestoreClient (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:128:39)
at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/index.js:315:26)
at ClientPool.acquire (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/pool.js:61:35)
at ClientPool.run (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/pool.js:114:29)
at Firestore.request (/riderequest/functions/node_modules/@google-cloud/firestore/build/src/index.js:957:33)
โ Your function was killed because it raised an unhandled error.
๊ด๋ จ stackoverflow ๊ฒ์๋ฌผ : https://stackoverflow.com/questions/56789424/the-incoming-json-object-does-not-contain-a-client-email-field
@noelmansour ๊ฐ์ฌํฉ๋๋ค. 7.0.1
์ 7.0.2
๋ฌธ์ ๊ฐ ๋ฐ์ํ ๊ฒ ๊ฐ์ต๋๋ค. ๋ณ๊ฒฝ ์ฌํญ์ ์ดํด ๋ณด๊ฒ ์ต๋๋ค.
๋ค์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ ๊ฒ ๊ฐ์ต๋๋ค. https://github.com/googleapis/google-auth-library-nodejs/issues/137
7.0.2 ์ดํ์๋์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค.
7.0.2๋ก ์
๊ทธ๋ ์ด๋ํ์ฌ ์ด๊ฒ๋ ๋ณผ ์ ์์ต๋๋ค. ๋ด ๊ณ์ ์๊ฒฉ ์ฆ๋ช
์ ํ์ธํ๊ณ client_email
ํ๋๊ฐ ์์ต๋๋ค.
๋๊ตฐ๊ฐ์ด ์ค๋ฅ๋ก ์ธํด ์คํจํ ์๋ฎฌ๋ ์ดํฐ์์ ์คํํ๋ ค๋ ํจ์์ ์ฝ๋๋ฅผ ๊ณต์ ํ ์ ์์ต๋๊น? ๊ฐ๋จํ ์๋ก ์ข์ต๋๋ค.
@samtstern ๋ค์ ์ฝ๋๊ฐ ์คํจํฉ๋๋ค.
import * as admin from 'firebase-admin';
admin.initializeApp();
import * as functions from 'firebase-functions';
export const testFunction = functions.https.onRequest(async (req, res) => {
const request = await admin.firestore().doc('test/123').get();
return request.ref.set({ test: 'random' })
.then(() => res.send('ok!'))
.catch((err) => res.status(500).send('error'));
});
admin.initializeApp()
ํธ์ถ ํ ๋ ์๋น์ค ๊ณ์ ์ ์ค์ ํ ๊ฒฝ์ฐ์๋ง ์๋ํฉ๋๋ค.
// this works
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
@wceolin ๊ฐ์ฌํฉ๋๋ค! ํจ์ ๋๋ ํ ๋ฆฌ์์ ๋ค์์ ์คํํ ์ ์์ต๋๊น?
$ npm list @google-cloud/firestore
์ด๊ฒ์ ๋ด ๊ฒฐ๊ณผ์ด๋ฉฐ ๋ชจ๋ ๊ฒ์ด ๋๋ฅผ ์ํด ์๋ํฉ๋๋ค.
functions@ /tmp/tmp.ZkMEM0XGPF/functions
โโโฌ [email protected]
โโโ @google-cloud/[email protected]
๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ์ป์์ต๋๋ค : ๐ค
๊ทธ๋์ ๋๋ ์ค๋ฅ ์คํ ์ถ์ ๊ณผ์ด ๊ธฐ๋ฅ์์ ๊ธธ์ ๊ฑท๊ณ ์์ต๋๋ค.
https://github.com/googleapis/gax-nodejs/blob/e1be4ebcc2287c61d5f1884033449e3b4e143242/src/grpc.ts#L141
์ด ๋ถ๊ธฐ๊ฐ ์์ต๋๋ค.
async _getCredentials(opts: ClientStubOptions) {
if (opts.sslCreds) {
return opts.sslCreds;
}
const grpc = this.grpc;
const sslCreds = grpc.credentials.createSsl();
const client = await this.auth.getClient();
const credentials = grpc.credentials.combineChannelCredentials(
sslCreds,
grpc.credentials.createFromGoogleCredential(client)
);
return credentials;
}
๋ด ์ฝ๋์์ opts.sslCreds
์ด ์ ์๋์ด ์์ผ๋ฏ๋ก์ด ๋ถ๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
if (opts.sslCreds) {
return opts.sslCreds;
}
์๊ฒฉ ์ฆ๋ช ์ ์กฐํฉํ๋ ค๊ณ ์๋ํ๊ณ ๋ฌธ์ ๋ฅผ ์ผ์ผํค๋ ๋ ๋ค๋ฅธ ์ง์ ์ ๋๋ค. ์ด์ ๋ด ์ฝ๋๊ฐ ํ ๋ฐฉํฅ์ผ๋ก ๊ฐ๊ณ ๋น์ ์ ์ฝ๋๊ฐ ๋ค๋ฅธ ๋ฐฉํฅ์ผ๋ก๊ฐ๋ ์ด์ ๋ฅผ ์์ ๋ด์ผํฉ๋๋ค.
@wceolin ์ node_modules
ํด๋์ ์ ๊ทผํ์ฌ createStub
์์ options
๊ฐ์ฒด๋ฅผ ์ธ์ํ๋ console.log()
ํ์ผ์ functions/node_modules/google-gax/build/src/grpc.js
๋ก ํธ์งํ์ฌ createStub
๊ธฐ๋ฅํ๊ณ ๋น์ ์ด ๋ณด๋ ๊ฒ์ ์๋ ค์ฃผ์ธ์?
์ง๊ธ๊น์ง ๋์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!
@samtstern ์ด๊ฒ์ด ๋์์ด๋๋์ง ํ์คํ์ง ์์ง๋ง ์ฃผ๋ง ๋์ package.json ๋ฐ node_modules๋ก ๋ง์ ์กฐ์ ์ ์ํํ์ต๋๋ค. 7.0.2์์ ๋ ์ด์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
npm list @google-cloud/firestore
์ถ๋ ฅ์ด ์ฌ์ฉ์์ ์ถ๋ ฅ๊ณผ ์ผ์นํฉ๋๋ค.
์ฃผ๋ง์ ๋ด node_modules ๋๋ ํ ๋ฆฌ๋ฅผ ๋ํฌํ๊ธฐ ๋๋ฌธ์ ๊ด๋ จ์ด ์๋์ง ๊ถ๊ธํฉ๋๋ค.
@noelmansour ๊ทธ ๋ฉ๋ชจ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๊นจ๋ํ ์ค์ ์์ ์ฌํ ํ ์์๋ ์ด์ ๋ฅผ ์ค๋ช ํฉ๋๋ค.
@noelmansour ๋๋ ๋ํ ๋ด node_modules
, yarn.lock
์ญ์ ํ๊ณ ์ข
์์ฑ์ ์ ๊ฑฐํ๋ ค๊ณ ์๋ํ์ง๋ง ์๋ํ์ง ์์์ต๋๋ค. ๋ฌด์จ ์ผ์ด ์ผ์ด๋๋์ง๋ณด๊ธฐ ์ํด ์ฒ์๋ถํฐ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
@noelmansour ์ด๊ฒ์ options
๊ฐ์ฒด์์ ์ป์ ๊ฒ์
๋๋ค.
{
"clientConfig": {},
"port":443,
"servicePath":"firestore.googleapis.com",
"credentials":{},
"projectId":"my-test-project",
"firebaseVersion":"8.2.0",
"libName":"gccl",
"libVersion":"2.2.3 fire/8.2.0",
"scopes":[
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/datastore"
]
}
@wceolin ๊ฐ์ฌํฉ๋๋ค. ์ด๊ฒ์ ๋ด ๋ชจ์ต (๊ทธ๋ฆฌ๊ณ ์ด๋ป๊ฒ ์๊ฒผ๋์ง)์ด๊ธฐ ๋๋ฌธ์ ๋งค์ฐ ๋์์ด๋ฉ๋๋ค.
{
"clientConfig":{},
"port":8080,
"servicePath":"localhost",
"credentials":{},
"projectId":"fir-dumpster",
"firebaseVersion":"8.2.0",
"libName":"gccl",
"libVersion":"2.2.3 fire/8.2.0",
"service":"firestore.googleapis.com",
"sslCreds":{
"callCredentials": {}
},
"customHeaders":{
"Authorization":"Bearer owner"
},
"scopes":[
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/datastore"
]
}
๋ณด์๋ค์ํผ ํด๋ผ์ด์ธํธ๊ฐ ์ฌ์ ํ ํ๋ก๋์ ์ก์ธ์ค๋ฅผ ์๋ํ๊ณ ์์ผ๋ฉฐ ํจ์ ์๋ฎฌ๋ ์ดํฐ๊ฐ์ด๋ฅผ ์ํ ํ ๊ถํ์ด ์๊ธฐ ๋๋ฌธ์ ์คํจํฉ๋๋ค.
Firestore ์๋ฎฌ๋ ์ดํฐ๋ ์คํํ๊ณ ์์ต๋๊น? Firestore ์๋ฎฌ๋ ์ดํฐ์ ์์ฑํ๋ ๊ฒ์ด ๋ชฉํ์ ๋๊น, ์๋๋ฉด ์ค์ ๋ก ํ๋ก๋์ Firestore์ ์์ฑ ํ์๊ฒ ์ต๋๊น?
์ค, ๋๋์ด ์ด๊ฑธ ์ฌํ ํ ์์์์ต๋๋ค! firebase emulators:start --only functions
์คํํ๋ฉด Firestore์ ์ฐ๊ธฐ๋ฅผ ์๋ํ๋ฉด์ด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ด ๋ก๊ทธ ๋ฉ์์ง๊ฐ ํ์๋ฉ๋๋ค.
โ The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
๋ ์ด์ ์ ํํ์ง๋ ์์ง๋ง (์ค๋ฅ๋ client_email์ ๊ดํ ๊ฒ์) ํ์ง๋ ์ฌ์ ํ ์ ํํฉ๋๋ค. ์ฌ๊ธฐ์์๋ ๋ค๋ฅธ ์ฌ๋๋ค๋์ด ๊ฒฝ๊ณ ๋ฅผ ๋ณผ ์ ์์ต๋๊น?
๋ค์์ ๋์์ด ๋ ์์๋ ๋ช ๊ฐ์ง ์ถ๊ฐ ์ ๋ณด์ ๋๋ค. ์ฃผ๋ง ๋์ .zshrc์ firestore ์๋ฎฌ๋ ์ดํฐ ํ๊ฒฝ ๋ณ์๋ฅผ ๋ช ์ ์ ์ผ๋ก ์ค์ ํ์ต๋๋ค.
export FIRESTORE_EMULATOR_HOST="localhost:8080"
์ ๊ฑฐํ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด๊ฒ์ firebase emulators:start
๋ช
๋ น์ ์ฌ์ฉํฉ๋๋ค.
@noelmansour --debug
ํด๋น ๋ช
๋ น์ ์คํํ๊ณ ์ฌ๊ธฐ์ ๋ก๊ทธ๋ฅผ txt
ํ์ผ๋ก ์ฒจ๋ถ ํ ์ ์์ต๋๊น?
@samtstern ๋๋ก๋ ์๋ฎฌ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ก๋์ ์์ ์ผ๋ถ ๋ฐ์ดํฐ๋ฅผ ์ค์ ํ๋ HTTP ํจ์๋ฅผ ๋ก์ปฌ๋ก ์ ๊ณตํ์ต๋๋ค (์ผ๋ฐ์ ์ผ๋ก ์ผ๋ถ ๋ฐ์ดํฐ ๋ง์ด๊ทธ๋ ์ด์ ์ํ). ๋๋ ์ฌ์ฉํ๊ณ ์๋ค :
firebase serve --only functions --project myProjectAlias
๋๋ ๊ทธ๊ฒ์ด ๊ทธ๋ ๊ฒ ์๋ํด์ผํ๋์ง (์ฐ๋ฆฌ๊ฐ ํ๋ก๋์ ์ ๋ฐ์ดํฐ๋ฅผ ์ธ ์ ์๋๋ก ํ์ฉ) ํ์คํ์ง ์์ง๋ง ์์ ์๋ ์๋ํ์ต๋๋ค. ๐
@wceolin 6.8.0
์ดํ ๋ฒ์ ์์ ๋ฒ ์ด initializeApp()
๋ก ์๋ํ์ง ์์์ผํ์ต๋๋ค. ๊ทธ ์ฌ์ฉ ์ฌ๋ก๋ ์์ง๋ง ๊ธฐ๋ณธ์ ์ผ๋ก ํ๋ก๋์
์ ๋ณดํธํ๋๋ก ์ตํธ ์ธ์ ๋ง๋๋ ๋ฐฉ๋ฒ์ ์ฐพ๊ณ ์ถ์ต๋๋ค.
๊ทธ๋ฌ๋ ๋๋์ด ์ค๋ฅ๊ฐ ์ง๊ธ ์ด๋์ ์ค๋์ง ์๊ฒ๋์ด ๊ธฐ์ฉ๋๋ค!
@samtstern ํ์ธํ๊ธฐ ์ํด FIRESTORE_EMULATOR_HOST
์ ์ค์ ํ์ง ์์ ์ํ์์ firebase emulators:start --debug
๋ฅผ ์คํํฉ๋๋ค. ๋ง์ต๋๊น?
์ณ์!
2019 ๋ 7 ์ 1 ์ผ ์์์ผ ์คํ 12:28 Noel Mansour [email protected] ์์ฑ :
@samtstern https://github.com/samtstern ํ์ธํ๊ธฐ ์ํด firebase๋ฅผ ์คํํ์ญ์์ค.
emulators : start --debug with the FIRESTORE_EMULATOR_HOST not set, right?โ
๋น์ ์ด ์ธ๊ธ ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๊ณ ์์ต๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ณ GitHub์์ ํ์ธํ์ธ์.
https://github.com/firebase/firebase-tools/issues/1451?email_source=notifications&email_token=ACATB2WV27VPIODNLGFS4TLP5JLGBA5CNFSM4H4GTWI2YY3PNVWWK3TUL52HS4DFWSVREXG4393VMVORBW63LNDYMVXHJK
๋๋ ์ค๋ ๋ ์์๊ฑฐ
https://github.com/notifications/unsubscribe-auth/ACATB2WG4EAD5KU7YRB5AUTP5JLGBANCNFSM4H4GTWIQ
.
์ฌ๊ธฐ์์ด.
์ฐธ๊ณ ๋ก์ด ์ค์์ project-id๋ฅผ ์ ๊ฑฐํ์ต๋๋ค (์ค์ํ๋ค๊ณ ์๊ฐํ์ง ๋ง์ญ์์ค).
[2019-07-01T19:32:42.859Z] >>> HTTP REQUEST GET https://mobilesdk-pa.googleapis.com/v1/projects/<project-id>:getServerAppConfig
๋ํ ์ธ๊ธ ํ ๊ฐ์น๊ฐ์๋ ๊ฒ์ env ๋ณ์๋ฅผ ๋ด ๋ณด๋ด์ง ์๊ณ [email protected]์์ ๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
โ Error: Getting metadata from plugin failed with error: Header field "authorization" must have only a single value
at Http2CallStream.call.on (/Users/noel/dev/snowble/functions/node_modules/@grpc/grpc-js/build/src/call.js:68:41)
at emitOne (events.js:121:20)
at Http2CallStream.emit (events.js:211:7)
at process.nextTick (/Users/noel/dev/snowble/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:71:22)
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
โ Your function was killed because it raised an unhandled error.
ํด๋น ๋ก๊ทธ์ ๋ํด @noelmansour ์๊ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ํจ์ ์ฝ๋๋ ๋ณด์ฌ ์ฃผ์๊ฒ ์ต๋๊น?
๋ด ๋ชจ๋ ๊ธฐ๋ฅ์ ๊ณต์ ํ์ง ์๊ธฐ ๋๋ฌธ์ ์ฝ๊ฐ ๊น๋ค ๋กญ๊ณ ์ง๊ธ์ ๊ฒฉ๋ฆฌ ์ํ์์ ์ค๋ฅ๊ฐ ์ฌํ๋๋์ง ํ์ธํ ์๊ฐ์ด ์์ง๋ง ์ฌ๊ธฐ์ ๋ด๊ฐ ์คํ ํ hello ๊ธฐ๋ฅ์ด ์์ต๋๋ค.
index.ts :
require('./common'); // this should always be first in this file
export * from './debug'
// other exports for other functions
common.ts :
import * as admin from 'firebase-admin';
export const app = admin.initializeApp();
debug.ts :
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import {app} from "./common";
export const hello = functions.https.onRequest(async (req, resp) => {
const firestore = app.firestore();
const users = await firestore.collection('users').get();
console.log('empty users collection? ' + users.empty);
resp.sendStatus(200);
});
package.json :
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"emulators": "npm run build && firebase emulators:start",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/tasks": "^1.1.0",
"@types/jsonwebtoken": "^8.3.2",
"@types/request-promise": "^4.1.42",
"firebase-admin": "^8.2.0",
"firebase-functions": "^3.0.2",
"request": "^2.88.0",
"request-promise": "^4.2.4"
},
"devDependencies": {
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
"private": true
}
@noelmansour ๊ฐ์ฌํฉ๋๋ค! ๊ทธ๊ฒ์ ๋์๊ฒ ๋ฒ๊ทธ๋ฅผ ๋๋ฌ๋๋ค. ์ด ๋ ๊ฐ์ง๋ ๋์ผํด์ผํ์ง๋ง ๋ค์์ ์๋๋๋ค.
์ต์ 1
admin.initializeApp();
const firestore = admin.firestore();
์ต์ 2
const app = admin.initializeApp();
const firestore = app.firestore();
๋ค, ๊ทธ๊ฒ์ ๋๋ฅผ ์ํด ๊ทธ๊ฒ์ ๊ณ ์ณค์ต๋๋ค. ๊ฐ์ฌ!
๋ํ Error: The incoming JSON object does not contain a client_email field
์ค๋ฅ๊ฐ ์์ต๋๋ค. ๊ณ ์น ์ ์์ต๋๋ค.
๊ธฐ๋ณธ ์ฝ๋ :
import { initializeApp } from 'firebase-admin';
// Initiate Firebase app
export const app = initializeApp();
export const db = app.firestore();
export const auth = app.auth();
๋ ๋ค๋ฅธ ์๋ :
import { initializeApp, firestore, auth as defAuth } from 'firebase-admin';
// Initiate Firebase app
export const app = initializeApp();
export const db = firestore();
export const auth = defAuth();
๋ ๋ค๋ฅธ ์๋ :
import * as admin from 'firebase-admin';
// Initiate Firebase app
export const app = admin.initializeApp();
export const db = admin.firestore();
export const auth = admin.auth();
@JFGHT ์๋ฎฌ๋ ์ดํฐ๋ฅผ ์คํํ๊ธฐ ์ํด ์ด๋ค ๋ช
๋ น์ ์ฌ์ฉํ๊ณ ์์ต๋๊น? --debug
ํ๋๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ ๋ช
๋ น ๋ฐ ์คํ ๋ก๊ทธ๋ฅผ ํ์ ํ ์ ์์ต๋๊น?
_ ๋ฉด์ฑ ์กฐํญ : ์ฌ๊ธฐ์ ๋ด ๋ฌธ์ ๊ฐ์ด ๋ฌธ์ ์ ์ด๋ค ๊ด๋ จ์ด ์๋์ง ํ์คํ์ง ์์ง๋ง, ์ ์ด๋ ์ผ๋ถ๋ ๋์์ด ๋ ์ ์์ผ๋ฏ๋ก ์ฌ๊ธฐ์ ๋ด ์ ๋ณด๋ฅผ ์ญ์ ํ ์ ์์ต๋๋ค ._
firestore ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ผ๋ถ ๋ฌธ์๋ฅผ ์ผ๊ด ์ ์ผ๋ก ์ ๋ฐ์ดํธํ๋ ค๊ณ ์๋ํ๋ firebase ํจ์์์ ๋์ผํ์ต๋๋ค. (๋ฐฐ์น์์ด ํ ์คํธํ์ง ์์์ต๋๋ค).
์ด๊ฒ์ ์ฝ ์คํ์ ๋๋ค.
Unhandled error Error: The incoming JSON object does not contain a client_email field
> at JWT.fromJSON (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-auth-library\build\src\auth\jwtclient.js:165:19)
> at GoogleAuth.fromJSON (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-auth-library\build\src\auth\googleauth.js:294:16)
> at GoogleAuth.getClient (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-auth-library\build\src\auth\googleauth.js:476:52)
> at GrpcClient._getCredentials (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-gax\build\src\grpc.js:107:40)
> at GrpcClient.createStub (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\google-gax\build\src\grpc.js:223:34)
> at new FirestoreClient (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\v1\firestore_client.js:128:39)
> at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\index.js:315:26)
> at ClientPool.acquire (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\pool.js:61:35)
> at ClientPool.run (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\pool.js:114:29)
> at Firestore.readStream (D:\thdk\Projects\timesheets\functions\node_modules\firebase-admin\node_modules\@google-cloud\firestore\build\src\index.js:995:26)
RESPONSE RECEIVED FROM FUNCTION: 500, {
"error": {
"status": "INTERNAL",
"message": "INTERNAL"
}
}
๋ช
๋ น ์ค์ ์ฌ์ฉํ์ฌ ๋ก์ปฌ์์ ํจ์๋ฅผ ์คํํ์ต๋๋ค.
firebase functions:shell
์ด ์ฝ๋๋ฅผ ์ฌ์ฉํ์ต๋๋ค.
// Reference report in Firestore
const db = admin.firestore();
admin.initializeApp();
export const performMyCallableFirebaseFunction = (db,, { from, to }) => {
return db.collection("collectionName").where("prop", "==", from).limit(500).get().then(snapshot => {
if (snapshot.empty) return new Promise(resolve => resolve(`No docs found with prop: ${from}`));
const batch = db.batch();
snapshot.forEach(doc => batch.update(doc.ref, { prop: to }));
return batch.commit();
});
};
exports.myCallableFirebaseFunction = functions.https.onCall(data => performMyCallableFirebaseFunction(db, data.from, data.to));
๋๋ ์ค์ ๋ฐ๊ฟจ๋ค
admin.initializeApp();
...์
admin.initializeApp({ credential: admin.credential.applicationDefault() });
์ด์ ๋ค์์ ์ฌ์ฉํ์ฌ ๋ด ํจ์๋ฅผ ๋ก์ปฌ๋ก ํธ์ถ ํ ์ ์์ต๋๋ค.
firebase functions:shell
firebase > myCallableFirebaseFunction({from: "foo", to: "bar"})
admin.credential.applicationDefault ()์ ๋ํ ๋ฌธ์๋ฅผ ์ฐธ์กฐํ์ญ์์ค.
๋ฟก๋ฟก
concurrently --kill-others 'GOOGLE_APPLICATION_CREDENTIALS=service-account.json firebase serve --only functions' 'tsc --project ./ --watch'
๋ก๊ทธ์ ๊ดํด์๋ ์ค๋์ด ๋ ์ ์์ต๋๋ค. ์ฃ์กํฉ๋๋ค!
๋๋ ์ค์ ๋ฐ๊ฟจ๋ค
admin.initializeApp();
...์
admin.initializeApp({ credential: admin.credential.applicationDefault() });
์ด๊ฒ์ ๋๋ฅผ ์ํด ์ผํ์ต๋๋ค. ๋ค์์ ํตํด ๋ก์ปฌ์์ ํจ์๋ฅผ ์คํํ๊ณ ์์ต๋๋ค.
firebase serve --only functions
์ด๊ฒ์ด ์์ฐ์ ์์ ํ์ง ํ์คํ์ง ์์ต๋๋ค. ๋ฌธ์์์ ํ๋ก๋์ ์์ ์คํ๋๋ ์ฝ๋์ ๋ํ ๊ด๋ฆฌ์ ์ก์ธ์ค ๊ถํ์ ๋ถ์ฌํ๋ ๊ฒ์ฒ๋ผ ๋ค๋ฆฌ์ง๋ง ์ด์จ๋ ์ฌ์ค์ ๋๋ค.
@ ralphsmith80 aah ์๋ง ๋ง์ต๋๋ค.
์๋์ผ๋ก ์๊ฒฉ ์ฆ๋ช ์ฐพ๊ธฐ
GCP ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์ ํ๋ฆฌ์ผ์ด์ ๊ธฐ๋ณธ ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด (ADC)๋ผ๋ ์ ๋ต์ ์ฌ์ฉํ์ฌ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด๋ฅผ ์ฐพ์ต๋๋ค. ์ฝ๋์์ ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ์ ๋ต์ ๋ค์ ์์๋ก ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด๋ฅผ ํ์ธํฉ๋๋ค.
๋จผ์ ADC๋ ํ๊ฒฝ ๋ณ์ GOOGLE_APPLICATION_CREDENTIALS๊ฐ ์ค์ ๋์ด ์๋์ง ํ์ธํฉ๋๋ค. ๋ณ์๊ฐ ์ค์ ๋๋ฉด ADC๋ ๋ณ์๊ฐ ๊ฐ๋ฆฌํค๋ ์๋น์ค ๊ณ์ ํ์ผ์ ์ฌ์ฉํฉ๋๋ค. ๋ค์ ์น์ ์์๋ ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ค๋ช ํฉ๋๋ค.
ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์ ๊ฒฝ์ฐ ADC๋ Compute Engine, Kubernetes Engine, App Engine, Cloud Functions๊ฐ ์ ๊ณตํ๋ ๊ธฐ๋ณธ ์๋น์ค ๊ณ์ ์ ํด๋น ์๋น์ค์์ ์คํ๋๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ฌ์ฉํฉ๋๋ค.
ADC๊ฐ ์์ ์๊ฒฉ ์ฆ๋ช ์ค ํ๋๋ฅผ ์ฌ์ฉํ ์ ์์ผ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ด ์ ๋ต์ ํ ์คํธ ๋ฐ ์คํ์ ์ ์ฉํ์ง๋ง ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ฌ์ฉ์ค์ธ ์๊ฒฉ ์ฆ๋ช ์ ์๋ณํ๊ธฐ ์ด๋ ต๊ฒ ๋ง๋ค ์ ์์ต๋๋ค.
์ถ์ฒ : https://cloud.google.com/docs/authentication/production
๋๋ ์ค์ ๋ฐ๊ฟจ๋ค
admin.initializeApp();
...์
admin.initializeApp({ credential: admin.credential.applicationDefault() });
์ด ๋ฐฉ๋ฒ์ ์์ ํ ์๋ก์ด ์ค๋ฅ๋ฅผ ๋ง๋ญ๋๋ค.
Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
at process._tickCallback (internal/process/next_tick.js:68:7)
# 1454์์ ์ธ๊ธ ํ๋๋ก ์คํ ์ด๋ฅผ ์ด๊ธฐํํ๊ณ ์์ต๋๋ค.
admin.initializeApp();
const db = admin.firestore();
initializeApp
์ถ๊ฐ ๋ ์๊ฒฉ ์ฆ๋ช
์ผ๋ก ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
๊ทธ๊ฒ ์์ด๋ ๋๋ ์ฌ์ ํ ์ป๊ณ ์๋ค.
Error: The incoming JSON object does not contain a client_email field
at JWT.fromJSON (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-auth-library/build/src/auth/jwtclient.js:165:19)
at GoogleAuth.fromJSON (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:294:16)
at GoogleAuth.getClient (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:476:52)
at GrpcClient._getCredentials (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-gax/build/src/grpc.js:107:40)
at GrpcClient.createStub (/Users/otanriverdi/Projects/socialpong/functions/node_modules/google-gax/build/src/grpc.js:223:34)
at new FirestoreClient (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:128:39)
at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/index.js:315:26)
at ClientPool.acquire (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/pool.js:61:35)
at ClientPool.run (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/pool.js:114:29)
at Firestore.readStream (/Users/otanriverdi/Projects/socialpong/functions/node_modules/@google-cloud/firestore/build/src/index.js:995:26)
๊ธฐ๋ณธ ์์ต์ (ํํ ๋ฆฌ์ผ์ 2019 ๋ 6 ์๋ถํฐ)์์ ์ด์ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฏ๋ก์ด ์ค๋ฅ๋ ๋งค์ฐ ์๋กญ์ต๋๋ค.
INDEX.JS :
```const functions = require ( 'firebase-functions');
const admin = require ( 'firebase-admin');
admin.initializeApp ();
admin.firestore()
.collection('screams')
.add(newScream)
.then(doc => {
res.json({message: `document ${doc.id} created successfully`});
})
.catch(err => {
res.status(500).json({ error: 'oops, something went wrong'});
console.error(err);
});
});
Postman์์ ์๋ ํฌ์ธํธ๋ฅผ ์คํํ๋ฉด ์ค๋ฅ ๋ฉ์์ง๊ฐ ๋ํ๋ฉ๋๋ค.
"์ค๋ฅ": "์ฃ์กํฉ๋๋ค. ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค."
์ฝ์์ ๋ค์๊ณผ ๊ฐ์ด ํ์๋ฉ๋๋ค.
ํจ์ : "createScream"์คํ ์์
์ค๋ฅ : ์์ JSON ๊ฐ์ฒด์ client_email ํ๋๊ฐ ์์ต๋๋ค.
ํํ ๋ฆฌ์ผ์ FreeCodeCamp์์์ ๋๋ค - https://www.youtube.com/watch?v=m_u6P5k0vP0
Firebase ์ฝ์> ์ค์ (ํฑ๋ ๋ฐํด ์์ด์ฝ)> ์ฌ์ฉ์ ๋ฐ ๊ถํ> ์๋น์ค ๊ณ์
์ ํค๋ฅผ ์์ฑํ์ญ์์ค.
ํ๋ก์ ํธ ํด๋์ json์ ์ถ๊ฐํ์ญ์์ค.
var admin = require("firebase-admin");
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://lts-profile.firebaseio.com"
});
์๋น์ค ๊ณ์ json ํ์ผ์ ํ๋ก์ ํธ์์ Firebase ์๋น์ค ๋ฐ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์๋๋กํฉ๋๋ค.
ํญ์ ๋น๊ณต๊ฐ ์ฌ์ผํฉ๋๋ค. .gitignore์ ํ์ผ ํฌํจ
Firebase ์ฝ์> ์ค์ (ํฑ๋ ๋ฐํด ์์ด์ฝ)> ์ฌ์ฉ์ ๋ฐ ๊ถํ> ์๋น์ค ๊ณ์
์ ํค๋ฅผ ์์ฑํ์ญ์์ค.
ํ๋ก์ ํธ ํด๋์ json์ ์ถ๊ฐํ์ญ์์ค.
var admin = require("firebase-admin"); var serviceAccount = require("path/to/serviceAccountKey.json"); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: "https://lts-profile.firebaseio.com" });
์๋น์ค ๊ณ์ json ํ์ผ์ ํ๋ก์ ํธ์์ Firebase ์๋น์ค ๋ฐ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์๋๋กํฉ๋๋ค.
ํญ์ ๋น๊ณต๊ฐ ์ฌ์ผํฉ๋๋ค. .gitignore์ ํ์ผ ํฌํจ
๊ฐ์ฌํฉ๋๋ค phtn, ๊ฐ์ฌํฉ๋๋ค. ์ง์นจ์ ๋ฐ๋์ง๋ง ์ด์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
Error: Error occurred while parsing your function triggers.
์ด์ํ๊ฒ๋ 'firebase deploy'๋ฅผ ์คํํ๋ฉด ๋ชจ๋ ๊ฒ์ด ์๋ํฉ๋๋ค. ' https : //europe-west1-myapp.cloudfunctions.net/api / ...- localhost๊ฐ ์๋๋๊น?
์ด ๋ ๊ฐ์ง ์๋ต์ ์กฐํฉ์ด ํจ๊ณผ๊ฐ์์์ต๋๋ค! ๋์ ์ฃผ์ ์ ๋ค์ ํ ๋ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
serviceAccountKey.json์ /functions
๋๋ ํฐ๋ฆฌ์ ์์ด์ผํฉ๋๋ค.
firebase deploy --only functions
๊ฐ ์ธ๋ถ์ ์์ผ๋ฉด ๋ถ๋ง์ ์ ๊ธฐํฉ๋๋ค.
๋ค์ ํ ๋ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๋ด serviceAccountKey.json์ / functions ํด๋์ ์์ต๋๋ค (์๋ ๋งํฌ์ screen-grab ์ฐธ์กฐ).
์ฑ์ ์ด๊ธฐํํ๋ ์ธ ๊ฐ์ง ๋ฐฉ๋ฒ์ด์๋ ๊ฒ ๊ฐ์ต๋๋ค.์ด ์ธ ๊ฐ์ง๋ฅผ ๋ชจ๋ ๊ฐ๋ณ์ ์ผ๋ก ์๋ํ์ง๋ง ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ด๊ฐ ๋์น๊ณ ์๋ ๋ฏธ์น ๋จ์ํ ์ผ์ด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋
ํ๋ฉด ์ก๊ธฐ :
์ฐ๋ฆฌ ์ชฝ์์๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ณ ์์ต๋๋ค. ์ด ๋ชจ๋ธ์์ firebase๋ฅผ ์ด๊ธฐํํฉ๋๋ค.
const firebaseInstance = admin.initializeApp ()
const firestoreInstance = firebaseInstance.firestore ()
์ด ๋ฌธ์ ๋ฅผ ์ถ์ ํ๋ ๋ฐ ๋์์ด๋๋ ์ ๋ณด๊ฐ ์์ผ๋ฉด ์๋ ค์ฃผ์ธ์.
์ด ์ค๋ ๋์ ๋ชจ๋ ์ฌ๋. ํด๊ฒฐ์ฑ ์ ์ฐพ์์ต๋๋ค. firebase-tools๋ฅผ 7.0.2์์ 7.0.1๋ก ๋ค์ด ๊ทธ๋ ์ด๋ํ๊ณ ์์ ํ ๋ค๋ฅธ ์ค๋ฅ (๊ธฐ๋ณธ ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด๋ฅผ๋ก๋ ํ ์ ์๋ค๋ ์ค๋ฅ)๋ฅผ ๋ฐ์์ต๋๋ค.
๊ทธ๋์ ์ฐ๋ฆฌ๋ ๊ณ์ํด์ ๋ค์์ ์คํํ์ต๋๋ค.
gcloud auth application-default login
์ด๋ก ์ธํด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค.
@ryanhornberger ๋ค์์ ์ํํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ต๋๋ค.
const firebaseInstance = admin.initializeApp()
const firestoreInstance = admin.firestore() // I changed this line
๋๋ # 1459์ ์ค๋ ๊ฒ์ ๋ํ ์์ ์ด ์์ต๋๋ค.
@samtstern ๊ฐ์ฌํฉ๋๋ค!
์ด ์ค๋ ๋์ ๋ชจ๋ ์ฌ๋. ํด๊ฒฐ์ฑ ์ ์ฐพ์์ต๋๋ค. firebase-tools๋ฅผ 7.0.2์์ 7.0.1๋ก ๋ค์ด ๊ทธ๋ ์ด๋ํ๊ณ ์์ ํ ๋ค๋ฅธ ์ค๋ฅ (๊ธฐ๋ณธ ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด๋ฅผ๋ก๋ ํ ์ ์๋ค๋ ์ค๋ฅ)๋ฅผ ๋ฐ์์ต๋๋ค.
๊ทธ๋์ ์ฐ๋ฆฌ๋ ๊ณ์ํด์ ๋ค์์ ์คํํ์ต๋๋ค.
gcloud auth application-default login
์ด๋ก ์ธํด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค.
์ด๊ฒ์ ๋๋ฅผ ์ํด ์๋ํฉ๋๋ค. ์ฒ์์๋ firebase-tools๋ฅผ 7.1๋ก ์ ๊ทธ๋ ์ด๋ํ๋๋ฐ ๋ก์ปฌ์์ 'firebase serve'๋ฅผ ์คํํ ๋ '๋์ผํ ์ค๋ฅ'๊ฐ ๋ฐ์ํ์ต๋๋ค. ๊ทธ๋ฌ๋ firebase์ ๋ฐฐํฌํ๋ฉด ์ ์๋ํฉ๋๋ค. 7.0.1๋ก ๋ค์ด ๊ทธ๋ ์ด๋ํ๋ฉด ๋ด ์ง์ญ์์ ์๋ํฉ๋๋ค.
7.1๊ณผ ๋์ผํ ๋ฌธ์
์์ ์์
์ค์ด์ง๋ง ์์ง ์ค๋น๋์ง ์์์ต๋๋ค.
https://github.com/firebase/firebase-tools/pull/1479
์ ๋ฐ ์ด๊ฑธ๋ก ๋ถ์ด ์์ด์, ์ด๋ค ๋ฐฉ๋ฒ ์ผ๋ก์?
7.0.1๋ก ๋ค์ด ๊ทธ๋ ์ด๋ํด๋ ๋์์ด๋์ง ์์์ต๋๋ค.
์ด์ ๋ํ ์์ ์ฌํญ์ด # 1479์ ๋ณํฉ๋์์ผ๋ฉฐ ๋ค์ ๋ฆด๋ฆฌ์ค์ ํฌํจ๋ ์์ ์
๋๋ค ( 7.2.0
).
์๋ ํ์ธ์ @samtstern , ์ ๊ฐ โโ์๋ชปํ๊ณ ์๋
๋จผ์ firebase emulators:exec "npm run test"
์คํํ ๋ ๋ค์ ๊ฒฝ๊ณ ๊ฐ ํ์๋ฉ๋๋ค.
โ The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
๋ช ๋ น์ ์๋ถ๋ถ์์ ์๋ฎฌ๋ ์ดํฐ๋ฅผ ์์ํ๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
~/d/s/functions โฏโฏโฏ firebase emulators:exec "npm run test" โ 130
i Starting emulators: ["functions","firestore"]
โ functions: Using node<strong i="12">@8</strong> from host.
โ functions: Emulator started at http://localhost:5001
i firestore: Logging to firestore-debug.log
โ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
์ค์ ๋ก ํ๋ก๋์ Firestore DB๋ฅผ ์ ๋ฐ์ดํธํ๋ ๊ฒ์ด ์๋๋๋ค. ์๋ง๋ ๊ฑฐ์ง ์์ฑ์ผ๊น์?
๋ค๋ฅธ ๋ฌธ์ ๋ ์ฌ์ ํ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค๋ ๊ฒ์
๋๋ค. $GOOGLE_APPLICATION_CREDENTIALS
์ค์ ํ์ง ์์์ง๋ง https://firebase.google.com/docs/functions/local-emulator#set_up_admin_credentials_optional ์ ๋ฐ๋ผ firestore์๋ง ์ก์ธ์คํ๋ ๊ฒฝ์ฐ ์ด๋ฏธ ์ถฉ๋ถํ ๊ถํ์ด ์์ด์ผํฉ๋๋ค.
Cloud Firestore ๋ฐ ์ค์๊ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค ํธ๋ฆฌ๊ฑฐ์๋ ์ด๋ฏธ ์ถฉ๋ถํ ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด๊ฐ ์์ผ๋ฉฐ ์ถ๊ฐ ์ค์ ์ด ํ์ํ์ง ์์ต๋๋ค.
admin.initializeApp();
์ฌ์ฉํ์ฌ ๋งค๊ฐ ๋ณ์์์ด ๊ด๋ฆฌ์ SDK๋ฅผ ์ด๊ธฐํํ๊ณ ์์ต๋๋ค. ๋ด๊ฐ ์๋ชปํ๊ณ ์๋ ์์
์ผ๊น์?
@noelmansour ์ด๊ฒ์๋ณด๊ณ master
!) ๋น์ ์ ์ฃผ ํจ์ ํ์ผ์ ์ฝ๋๋ฅผ ๋ณด์ฌ์ค ์ ์์ต๋๊น?
๊ฑฐ์ ํ์คํ๊ฒ ์์์ฑ์ด์ง๋ง ์ฐ๋ฆฌ๊ฐ ๊ณ ์ณ์ผ ํ ์ค์ํ ๊ฒ์ ๋๋ค.
๋ค๋ฅธ ํ์ผ์์ ๋ด๋ณด๋ด๋ ๊ฒ์ด๋ฏ๋ก ๋งค์ฐ ์ต์ํ๋ฉ๋๋ค.
import * as admin from 'firebase-admin';
// this should happen before any function runs
admin.initializeApp();
export * from './authFunctions';
export * from './fitbit';
export * from './sleep'
export * from './scheduler';
export * from './debug'
export {scheduleFunction} from "./scheduler";
์ค์ ๋ก ๋ด ํ
์คํธ ์ค์ ์ ๋ฌธ์ ๊ฐ์๋ ๊ฒ ๊ฐ์ต๋๋ค. firebase emulators:start
์คํ์ ๊ฒฝ๊ณ ๊ฐ ํ์๋์ง ์์ต๋๋ค.
@noelmansour ํ ์คํธ๋ ์ด๋ป๊ฒ ์๊ฒผ์ต๋๊น? ๋ํ์ด ์ค๋ ๋์ ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ์คํธ ๋ฉ์ผ์ ๋ณด๋ด์ง ์๋๋ก์ด ๋ฌธ์ ๋ฅผ ๋ ผ์ํ๊ธฐ ์ํด ์๋ก์ด ๋ฌธ์ ๋ฅผ ์ ์ถํ ์ ์์ต๋๋ค.>
์, ๋ฌผ๋ก ์ ๋๋ค. ์ฃ์กํฉ๋๋ค. # 1530 ๊ฐ์ฅ
์ด ์ค๋ ๋์ ๋ชจ๋ ์ฌ๋. ํด๊ฒฐ์ฑ ์ ์ฐพ์์ต๋๋ค. firebase-tools๋ฅผ 7.0.2์์ 7.0.1๋ก ๋ค์ด ๊ทธ๋ ์ด๋ํ๊ณ ์์ ํ ๋ค๋ฅธ ์ค๋ฅ (๊ธฐ๋ณธ ์ฌ์ฉ์ ์ธ์ฆ ์ ๋ณด๋ฅผ๋ก๋ ํ ์ ์๋ค๋ ์ค๋ฅ)๋ฅผ ๋ฐ์์ต๋๋ค.
๊ทธ๋์ ์ฐ๋ฆฌ๋ ๊ณ์ํด์ ๋ค์์ ์คํํ์ต๋๋ค.gcloud auth application-default login
์ด๋ก ์ธํด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค.
์ด๊ฒ์ ๋๋ฅผ ์ํด ์๋ํฉ๋๋ค. ์ฒ์์๋ firebase-tools๋ฅผ 7.1๋ก ์ ๊ทธ๋ ์ด๋ํ๋๋ฐ ๋ก์ปฌ์์ 'firebase serve'๋ฅผ ์คํํ ๋ '๋์ผํ ์ค๋ฅ'๊ฐ ๋ฐ์ํ์ต๋๋ค. ๊ทธ๋ฌ๋ firebase์ ๋ฐฐํฌํ๋ฉด ์ ์๋ํฉ๋๋ค. 7.0.1๋ก ๋ค์ด ๊ทธ๋ ์ด๋ํ๋ฉด ๋ด ์ง์ญ์์ ์๋ํฉ๋๋ค.
ํ์ด์ด๋ฒ ์ด์ค ๋ฒ์ ์ ๋ค์ด ๊ทธ๋ ์ด๋ํ๋ ๋ฐฉ๋ฒ์ ์๋ ค ์ฃผ์๊ฒ ์ต๋๊น? ๋ด ํ์ฌ ๋ฒ์ ์ 7.0.2์ด๊ณ npm i [email protected] -g this ์ค์น๋ฅผ ์๋ํ์ต๋๋ค. ํ์ง๋ง ์ฌ์ ํ ๋ด ๋ฒ์ ์ 7.0.2์ ๋๋ค. pls ๋์์ ๋ค์ด ๊ทธ๋ ์ด๋ํ๋ ๋ฐฉ๋ฒ?
์ด ๋ฌธ์ ์ ๋ํ ์ ์ฒด ํฝ์ค๋ 7.2.0
์ ๋ฆด๋ฆฌ์ค๋์์ต๋๋ค.
npm install -g [email protected]
ํด๋น ๋ฒ์ ์์ ์ฌ์ ํ ์ ์ฌํ ๋ฒ๊ทธ๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ ์ ๋ฌธ์ ๋ฅผ์ฌ์ญ์์ค.
Firebase ํจ์์ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์ด๋ฏธ npm install -g [email protected]์ ์๋ํ์ฌ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
Firebase ํจ์์ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์ด๋ฏธ npm install -g [email protected]์ ์๋ํ์ฌ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.
๋ค์ ์๋ฃจ์ ์ด ์ ์๊ฒ ํจ๊ณผ์ ์ด์์ต๋๋ค.
// Create Firebase-adminsdk key
// Providing a service account object inline
admin.initializeApp({
credential: admin.credential.cert({
projectId: "<PROJECT_ID>",
clientEmail: "foo@<PROJECT_ID>.iam.gserviceaccount.com",
privateKey: "-----BEGIN PRIVATE KEY-----<KEY>-----END PRIVATE KEY-----\n"
})
});
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
_ ๋ฉด์ฑ ์กฐํญ : ์ฌ๊ธฐ์ ๋ด ๋ฌธ์ ๊ฐ์ด ๋ฌธ์ ์ ์ด๋ค ๊ด๋ จ์ด ์๋์ง ํ์คํ์ง ์์ง๋ง, ์ ์ด๋ ์ผ๋ถ๋ ๋์์ด ๋ ์ ์์ผ๋ฏ๋ก ์ฌ๊ธฐ์ ๋ด ์ ๋ณด๋ฅผ ์ญ์ ํ ์ ์์ต๋๋ค ._
firestore ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ผ๋ถ ๋ฌธ์๋ฅผ ์ผ๊ด ์ ์ผ๋ก ์ ๋ฐ์ดํธํ๋ ค๊ณ ์๋ํ๋ firebase ํจ์์์ ๋์ผํ์ต๋๋ค. (๋ฐฐ์น์์ด ํ ์คํธํ์ง ์์์ต๋๋ค).
์ด๊ฒ์ ์ฝ ์คํ์ ๋๋ค.
๋ช ๋ น ์ค์ ์ฌ์ฉํ์ฌ ๋ก์ปฌ์์ ํจ์๋ฅผ ์คํํ์ต๋๋ค.
firebase functions:shell
์ด ์ฝ๋๋ฅผ ์ฌ์ฉํ์ต๋๋ค.
๋๋ ์ค์ ๋ฐ๊ฟจ๋ค
admin.initializeApp();
...์
admin.initializeApp({ credential: admin.credential.applicationDefault() });
์ด์ ๋ค์์ ์ฌ์ฉํ์ฌ ๋ด ํจ์๋ฅผ ๋ก์ปฌ๋ก ํธ์ถ ํ ์ ์์ต๋๋ค.
admin.credential.applicationDefault ()์ ๋ํ ๋ฌธ์๋ฅผ ์ฐธ์กฐํ์ญ์์ค.