Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions actions/supabase/queries/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ export async function sendInviteEmail(email: string) {
}

export async function checkIfUserExists(email: string): Promise<boolean> {
const supabase = await getSupabaseServerClient();
// called from reset-password before anyone is logged in, so RLS would
// hide every profile; use the admin client
const adminClient = getSupabaseAdminClient();
const lowerCaseEmail = email.toLowerCase();

const { data, error } = await supabase
const { data, error } = await adminClient
.from("profile")
.select("*")
.eq("email", lowerCaseEmail)
Expand Down
10 changes: 7 additions & 3 deletions actions/supabase/queries/invites.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use server";

import type { UUID } from "@/types/schema";
import supabase from "@/app/api/supabase/createClient";
import {
findAuthUserByEmail,
getSupabaseAdminClient,
getSupabaseServerClient,
} from "@/lib/supabase/server";
import { UserType } from "@/types/schema";
import { sendInviteEmail } from "./auth";
Expand Down Expand Up @@ -75,7 +75,9 @@ export async function submitNewInvite(
// deleted). It would make inviteUserByEmail fail, so remove it first.
await deleteAuthUserByEmail(email);

// create a row in invite table
// create a row in invite table (as the logged-in user, so RLS checks they
// are staff of this user group)
const supabase = await getSupabaseServerClient();
const { error } = await supabase.from("invite").upsert(
{
invite_id: id,
Expand Down Expand Up @@ -109,7 +111,7 @@ export async function submitNewInvite(
}

export async function changeToFacilitator(user_id: UUID): Promise<void> {
const { error } = await supabase
const { error } = await getSupabaseAdminClient()
.from("profile")
.update({ user_type: "Facilitator" })
.match({ id: user_id });
Expand All @@ -123,6 +125,7 @@ export async function changeToFacilitator(user_id: UUID): Promise<void> {
}

export async function deleteInvite(invite_id: UUID): Promise<void> {
const supabase = await getSupabaseServerClient();
const { error } = await supabase
.from("invite")
.delete()
Expand All @@ -149,6 +152,7 @@ export async function deleteAuthUserByEmail(email: string): Promise<void> {

export async function fetchInvites(user_group_id: UUID) {
try {
const supabase = await getSupabaseServerClient();
const { data, error } = await supabase
.from("invite")
.select("*")
Expand Down
2 changes: 1 addition & 1 deletion components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { CircularProgress } from "@mui/material";
import supabase from "@/actions/supabase/client";
import {
addUserToChatRoom,
checkRoomExists,
Expand All @@ -10,7 +11,6 @@ import {
fetchChatUserOptions,
fetchParticipantPhaseIndex,
} from "@/actions/supabase/queries/sessions";
import { supabase } from "@/lib/supabase/client";
import { ChatMessage, ChatParticipant, UUID } from "@/types/schema";
import { useProfile } from "@/utils/ProfileProvider";
import { useAnnouncements } from "@/utils/UseAnnouncements";
Expand Down
2 changes: 1 addition & 1 deletion utils/UseAnnouncements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { useMemo } from "react";
import { v5 as uuidv5 } from "uuid";
import supabase from "@/actions/supabase/client";
import { persistChatMessage } from "@/actions/supabase/queries/chat";
import { supabase } from "@/lib/supabase/client";
import { ChatMessage } from "@/types/schema";
import { EVENT_MESSAGE_TYPE, useRealtimeChat } from "./UseChat";

Expand Down
2 changes: 1 addition & 1 deletion utils/UseChat.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use client";

import { useCallback, useEffect, useRef, useState, useTransition } from "react";
import supabase from "@/actions/supabase/client";
import {
getMessageHistory,
persistChatMessage,
} from "@/actions/supabase/queries/chat";
import { supabase } from "@/lib/supabase/client";
import { ChatMessage } from "@/types/schema";

export const EVENT_MESSAGE_TYPE = "message";
Expand Down Expand Up @@ -40,7 +40,7 @@
};

sendQueuedMessages();
}, [isConnected, channel, roomId, initializingMessages]);

Check warning on line 43 in utils/UseChat.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

React Hook useEffect has a missing dependency: 'sendMessageObject'. Either include it or remove the dependency array

Check warning on line 43 in utils/UseChat.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

React Hook useEffect has a missing dependency: 'sendMessageObject'. Either include it or remove the dependency array

useEffect(() => {
if (!roomId || roomId === "announcements") {
Expand All @@ -54,7 +54,7 @@
try {
const messageHistory = await getMessageHistory(roomId, null, 50);
setChatMessages(messageHistory);
} catch (error) {

Check warning on line 57 in utils/UseChat.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

'error' is defined but never used

Check warning on line 57 in utils/UseChat.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

'error' is defined but never used
setChatMessages([]);
}
});
Expand Down
Loading