Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Messages V2] Migrate data layer #4036

Open
benfurber opened this issue Dec 12, 2024 · 4 comments
Open

[Messages V2] Migrate data layer #4036

benfurber opened this issue Dec 12, 2024 · 4 comments

Comments

@benfurber
Copy link
Member

benfurber commented Dec 12, 2024

Context

On profiles atm, messages can be sent to spaces.

  1. User completes the form.
  2. A message document is created on firebase.
  3. Firebase function onCreate then retreives the receiver email address and creates an email document (if certain checks are passed).
  4. The message doc is updated to say the message has been sent.
  5. (We hope) that the email plugin for the firestore sends the email.

Goal

Replace steps 2-5 with supabase and related tools.

New workflow

  1. User completes the form.
  2. A message item is created on supabase via an api call.
  3. On receipt of creation. The current checks in functions/src/messages/messages.ts take place.
  4. If three is fine, a webhook to an email service is sent.
  5. If three fails, the message is updated with the message fail reason
  6. Optional: Have resend update the DB when sent sucessfully

Schema

Current -> new

_id -> id
_created -> created_at
email -> sender_email
name? -> sender_name?
text -> message_body
toUserName -> receiver_user_name
(new) -> receiver_email
isSent -> status

What email service to use

I believe it makes sense to use Resend. Lots of services could do this for us, the advantage of resend is that it's a great option for the auth email service as it has a great intergration with supabase. It'll cost a flat $20 a month for everything we'll end up needing.

@benfurber
Copy link
Member Author

Description updated after chat with @mariojsnunes

@mariojsnunes
Copy link
Contributor

could we store the user email in the profiles table now? (since it's no longer exposed to the frontend)
then we could just have receiver_id and sender_id instead of receiver_user_name, receiver_email, sender_name, sender_email

@benfurber
Copy link
Member Author

@mariojsnunes Yes! I'm still not back into SQL thinking and should be joining. I think the email address should stay in the auth record though. e.g. something like this for the data the email service would need:

supabase.from('messages').select(`
  id,
  body,
  etc.
  receiver (
    auth (
      email
    )
  )
  sender (
    auth (
      email
    )
  )
`)

Though of course that then makes the auth work a dependency of this. Maybe unavoidable.

@benfurber benfurber removed their assignment Dec 13, 2024
@benfurber
Copy link
Member Author

Blocked until auth is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants