Skip to content

Commit

Permalink
username bug fix & images upload by id
Browse files Browse the repository at this point in the history
  • Loading branch information
Ketchupchh committed Jan 11, 2024
1 parent 993d150 commit 490a708
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/lib/context/auth-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
getDoc,
setDoc,
onSnapshot,
serverTimestamp
serverTimestamp,
getDocs,
query,
where,
limit
} from 'firebase/firestore';
import { auth } from '@lib/firebase/app';
import {
Expand Down Expand Up @@ -67,11 +71,15 @@ export function AuthContextProvider({

randomUsername = `${normalizeName as string}${randomInt}`;

const randomUserSnapshot = await getDoc(
doc(usersCollection, randomUsername)
const randomUserSnapshot = await getDocs(
query(
usersCollection,
where('username', '==', randomUsername),
limit(1)
)
);

if (!randomUserSnapshot.exists()) available = true;
if (randomUserSnapshot.empty) available = true;
}

const userData: WithFieldValue<User> = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/firebase/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export async function uploadImages(

const { id, name: alt, type } = file;

const storageRef = ref(storage, `images/${userId}/${alt}`); // You can use any name you want. i just kept it as 'images'.
const storageRef = ref(storage, `images/${userId}/${id}`); // You can use any name you want. i just kept it as 'images'.

try {
src = await getDownloadURL(storageRef);
Expand Down

0 comments on commit 490a708

Please sign in to comment.