Skip to content

Commit

Permalink
edit post route guard for owners of post
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandyrzph committed Aug 2, 2022
1 parent 780071d commit 1061c7b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pixelplace/src/components/Forms/PostEditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Formik, Form, Field } from "formik";
import { CreateEditPostSchema } from "../../utils/formValidators";
import { useEffect, useRef, useState } from "react";
import { AiOutlineCloudUpload } from "react-icons/ai";
import { useNavigate, useParams } from "react-router-dom";
import { Navigate, useNavigate, useParams } from "react-router-dom";
import { db, storage } from "../../firebase";
import { doc, updateDoc } from "firebase/firestore";
import { ref, uploadBytes, getDownloadURL } from "firebase/storage";
Expand All @@ -20,6 +20,7 @@ const PostEditForm = () => {
const fileRef = useRef(null);
const { postId } = useParams();


useEffect(() => {
if (image) {
const reader = new FileReader();
Expand All @@ -39,7 +40,12 @@ const PostEditForm = () => {
})
.catch((err) => console.log(err));
}, [postId]);


if (post?.ownerId !== user.uid) {
return <Navigate to="/" />
}

const uploadImage = async (image) => {
const imageRef = ref(storage, `${new Date().getTime() + image.name}`);
try {
Expand Down

0 comments on commit 1061c7b

Please sign in to comment.