V8
This is a really bad name! Of course we have a server (most of the time more than one)
Serverless means we have no configuration to do on our end manually until we need it!
Run the following commands to be presented within a CLI, then choose the options that matches your needs!
import { firestore } from '@/config/firebase'
// Create
firestore
.collection('users')
.add({ name: 'Patrick', email: 'patrick@email.com' })
// Read
firestore
.collection('users')
.get()
// Update
// One or more attributes
firestore
.doc('users/YEQijU76K8fshla3fUFngYjZQsBA')
.update({ name: 'Patrick Santos' })
// Set all attributes
firestore
.doc('users/YEQijU76K8fshla3fUFngYjZQsBA')
.set({ name: 'Patrick Santos', email: 'patrick@outroemail.com' })
// Delete
firestore
.doc('users/YEQijU76K8fshla3fUFngYjZQsBA')
.delete()
import { firestore } from '@/config/firebase'
// Full-text search
firestore
.collection('users')
.orderBy('createdAt')
.startAt('PAT') // uppercase
.endAt('pat\uf8ff') // lowercase
.limit(10)
SELECT * FROM users WHERE name ILIKE 'pat%';
yarn add algoliasearch react-instantsearch-dom
yarn add @types/react-instantsearch-dom --dev
import algoliasearch from 'algoliasearch/lite';
import { InstantSearch, SearchBox, Hits } from 'react-instantsearch-dom';
const searchClient = algoliasearch('PROJECT_ID', 'SEARCH_API_KEY');
const App = () => (
<InstantSearch searchClient={searchClient} indexName="collection_name">
<SearchBox />
<Hits />
</InstantSearch>
);
import * as functions from "firebase-functions"
export const helloWorld = functions.https
.onRequest((request, response) => {
response.send("My first cloud functions!");
});
// firebase deploy --only "functions:helloWorld"
# set an env variable
firebase functions:config:set some.path=value
# get all env variables into a file
firebase functions:config:get > .runtimeconfig.json
# windows: firebase functions:config:get | sc .runtimeconfig.json
import * as functions from "firebase-functions";
functions.config().some.path
# setup new environment in same project
firebase use --add
# after running this,
# all deploy commands will point to another env
firebase use production
import * as functions from "firebase-functions";
export const sendWelcomeEmail = functions
.auth.user().onCreate((user) => {
// ...
});
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
function isOwner(userId) {
return request.auth.uid == userId;
}
match /users/{userId} {
allow read: if true
allow create: if true
allow update, delete: if isSignedIn() && isOwner(userId)
}
}
}