This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MeetingCodec.ts | |
import * as T from 'io-ts' | |
import BaseMeetingCodecT from '../../shared/codecs/BaseMeetingCodec' | |
import JustStartTimeT from './JustStartTimeCodec' | |
const MeetingT = T.intersection([BaseCodecT, JustStartTimeT]) | |
export default MeetingT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The type we get from on retrieving the document from firestore: | |
type FromFirestore = { | |
"meetingAgenda": string | |
"startTime": firestore.Timestamp // 😱 This is a different type between the client and the admin sdks. | |
} | |
// The type we want in in our Frontend and Backend: | |
type Meeting = { | |
meetingAgenda: string, | |
startTime: Luxon.DateTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rules_version = '2'; | |
service cloud.firestore { | |
match /databases/{database}/documents { | |
match /users/{userId} { | |
allow read: if request.auth != null | |
match /private/info { | |
allow write: if request.auth && request.auth.uid == userId | |
allow read: if request.auth && request.auth.uid == userId | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Collection at /users/rzJZAyMbXaeXQ9OWeIckM88DUcq1 | |
{ | |
"name": "Rupert", // I'm happy for people to see this | |
} | |
// Collection at /users/rzJZAyMbXaeXQ9OWeIckM88DUcq1/private/info | |
{ | |
"email": "me@example.com", // I can be hidden now! | |
"birthday": "1970-01-01" // I can be hidden now! | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const superSecretEmail = userDoc.data().email. // 😱 | |
const superSecretBirthday = userDoc.data().birthday // 😱 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const userDoc = await getDoc(doc(db, '/users/', uid)) | |
const name = userDoc.data().name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Collection at /users/rzJZAyMbXaeXQ9OWeIckM88DUcq1 | |
{ | |
"name": "Rupert", // I'm happy for people to see this | |
"email": "me@example.com", // I'd rather they didn't see this | |
"birthday": "1970-01-01" // I'd rather they didn't see this | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as T from 'io-ts' | |
import BaseMeetingCodecT from '../../shared/codecs/BaseMeetingCodec' | |
import JustStartTimeT from './JustStartTimeCodec' | |
const MeetingT = T.intersection([BaseCodecT, JustStartTimeT]) | |
export default MeetingT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client LuxonTimestampCodec: | |
import * as T from 'io-ts' | |
import { DateTime } from 'luxon' | |
import { Timestamp } from 'firebase/firestore' | |
const LuxonDateTimeT = new T.Type<DateTime, Timestamp, unknown>( | |
'LuxonDateTimeT', | |
(u: unknown): u is DateTime => u instanceof DateTime, | |
(u: unknown, c: T.Context) => { | |
if (!(u instanceof Timestamp)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Backend TimestampCodec | |
import * as T from 'io-ts' | |
import { DateTime } from 'luxon' | |
import * as admin from 'firebase-admin' | |
export const LuxonDateTimeT = new T.Type<DateTime, admin.firestore.Timestamp, unknown>( | |
'LuxonDateTimeT', | |
(u: unknown): u is DateTime => u instanceof DateTime, | |
(u: unknown, c: T.Context) => { | |
if (!(u instanceof admin.firestore.Timestamp)) { |
NewerOlder