Skip to content

Commit

Permalink
layout fixes + firestore rules + sign-in bug
Browse files Browse the repository at this point in the history
  • Loading branch information
codyzu committed Jun 12, 2023
1 parent 091152e commit fdf3b8e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 22 deletions.
11 changes: 9 additions & 2 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@
}
]
}
]
}
],
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"storage": {
"rules": "storage.rules"
}
}
4 changes: 4 additions & 0 deletions firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"indexes": [],
"fieldOverrides": []
}
31 changes: 31 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
rules_version = '2';

service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
match /presentations/{presentation} {
allow read: if true;

allow create: if request.auth != null
// TODO: should this be aligned with all the possible fields?
&& request.resource.data.keys().hasAll(['uid', 'created', 'username', 'pages', 'notes', 'title'])
&& request.resource.data.keys().hasOnly(['uid', 'created', 'username', 'pages', 'notes', 'title'])
&& request.auth.uid == request.resource.data.uid;

// allow update: if request.auth != null;

allow update: if request.auth != null
&& request.auth.uid == resource.data.uid
&& request.resource.data.diff(resource.data).affectedKeys().hasOnly(['original', 'pages', 'rendered', 'title', 'notes', 'username']);

allow delete: if request.auth != null
&& request.auth.uid == resource.data.uid;
}
match /users/{userId} {
allow write: if request.auth != null && request.auth.uid == userId;
allow read: if request.auth != null && request.auth.uid == userId;
}
}
}
3 changes: 2 additions & 1 deletion src/layouts/DefaultLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function DefaultLayout({
<div>
<button
className={clsx(
'btn py-1 shadow-md',
'btn py-1 shadow-md flex flex-col items-center',
showUserMenu && 'bg-teal rounded-b-none',
)}
type="button"
Expand All @@ -82,6 +82,7 @@ export default function DefaultLayout({
showUserMenu ? 'text-black' : 'text-teal',
)}
/>
<div className="leading-none text-sm">account</div>
</button>
<div
className={clsx(
Expand Down
6 changes: 5 additions & 1 deletion src/pages/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ export default function SignIn() {
setEmailSent(true);
}}
>
<label className="flex flex-row gap-2 items-center">
Email:
<input
className="input w-auto"
className="input w-auto invalid:(border-red-700 shadow-red-700) invalid-focus:(border-red-700 shadow-red-700)"
id="email"
type="email"
placeholder="email address..."
value={email}
Expand All @@ -128,6 +131,7 @@ export default function SignIn() {
setEmail(event.target.value);
}}
/>
</label>
{isLink ? (
<button className="btn" type="submit">
Verify & Sign In
Expand Down
39 changes: 21 additions & 18 deletions src/pages/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function Export() {
const userSnapshot = await getDoc(doc(firestore, 'users', user.uid));
if (!userSnapshot.exists()) {
setUserData({});
return;
}

setUserData(userSnapshot.data() as UserDoc);
Expand Down Expand Up @@ -283,26 +284,28 @@ export default function Export() {
<div className="overflow-hidden flex flex-col items-center p-4 gap-6 pb-10 w-full max-w-screen-md mx-auto">
{!file && (
<div
className="btn rounded-md p-8 flex flex-col items-center justify-center w-full max-w-screen-sm aspect-video gap-4 cursor-pointer mx-6"
className="btn rounded-md p-8 flex w-full max-w-screen-sm aspect-video gap-4 cursor-pointer mx-6"
{...getRootProps()}
>
<input {...getInputProps()} />
{isDragActive ? (
<>
<div className="i-tabler-arrow-big-down-lines text-6xl animate-bounce animate-duration-500 text-teal-500" />
<div className="text-center">
Drop the pdf presentation here...
</div>
</>
) : (
<>
<div className="i-tabler-arrow-big-down-lines text-6xl animate-bounce" />
<div className="text-center">
Drag &apos;n&apos; drop a pdf presentation here, or click to
select a pdf presentation
</div>
</>
)}
<label className="flex flex-col items-center justify-center w-full">
{isDragActive ? (
<>
<div className="i-tabler-arrow-big-down-lines text-6xl animate-bounce animate-duration-500 text-teal-500" />
<div className="text-center">
Drop the pdf presentation here...
</div>
</>
) : (
<>
<div className="i-tabler-arrow-big-down-lines text-6xl animate-bounce" />
<div className="text-center">
Drag &apos;n&apos; drop a pdf presentation here, or click
to select a pdf presentation
</div>
</>
)}
<input {...getInputProps()} />
</label>
</div>
)}
{file && (
Expand Down
17 changes: 17 additions & 0 deletions storage.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
rules_version = '2';

// Craft rules based on data in your Firestore database
// allow write: if firestore.get(
// /databases/(default)/documents/users/$(request.auth.uid)).data.isAdmin;
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if false;
}
match /presentations/{presentationId}/{imageId} {
allow read: if true;
allow write: if request.auth != null
&& firestore.get(/databases/(default)/documents/presentations/$(presentationId)).data.uid == request.auth.uid;
}
}
}

0 comments on commit fdf3b8e

Please sign in to comment.