AthletiFi / athletifi-website

Official website for AthletiFi
https://www.athleti.fi
1 stars 5 forks source link

Referral Feature (Invite a Friend) #176

Closed qisforq closed 2 weeks ago

qisforq commented 3 months ago

Objective

Enable users to share access to their player cards with others via email invitations, allowing invited users to create an account and view the shared cards. The original user should have the ability to revoke access for invited users at any time.

Tasks

This feature has been broken down into the following tasks:

qisforq commented 2 months ago

@pm-moyanor the back-end component of this task seems pretty major - and I also am not quite sure how to implement it. That part might need to wait until user login is complete. I'd say start doing what you can with this task, and we'll assess once we hit a roadblock.

qisforq commented 2 months ago

@pm-moyanor for the email component of this task, we might be able to use Strapi. @HectorAgudelo and I have already implemented a few automated emails so we can work with you on that part

HectorAgudelo commented 2 months ago

To implement the feature you described, where users can share cards via email and manage access through your application, you'll need to integrate several components, including your Next.js frontend, AWS backend, PostgreSQL database, and potentially an email service like Strapi. Let's break down the steps to achieve this:

1. Database Schema Design

You'll need to adjust your PostgreSQL schema to manage the relationships between users, cards, and shared access. Here’s a basic schema idea:

CREATE TABLE users (
    user_id SERIAL PRIMARY KEY,
    email VARCHAR(255) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL
);

CREATE TABLE cards (
    card_id SERIAL PRIMARY KEY,
    creator_user_id INTEGER REFERENCES users(user_id),
    card_data JSONB
);

CREATE TABLE shared_cards (
    card_id INTEGER REFERENCES cards(card_id),
    recipient_user_id INTEGER REFERENCES users(user_id),
    access_granted TIMESTAMP DEFAULT NOW(),
    PRIMARY KEY (card_id, recipient_user_id)
);

2. Backend Logic with AWS and Strapi

3. Email Handling

When a card is shared:

4. Frontend Implementation with Next.js and TypeScript

5. Revoking Access

6. Using AWS Effectively

By integrating these components, your feature should be robust and scalable. AWS offers a comprehensive set of tools that can handle authentication, database management, serverless computing, and email services, making it a suitable full-stack solution for your application.

qisforq commented 2 months ago

Image

The only thing not accounted for in this diagram is if we want to add timestamps for when an invitation is sent, accepted, and revoked

qisforq commented 2 months ago

Backend - Hector / Paula (emails) / Louis Database - Quentin / Hector Frontend - Paula / Hector

chef-louis commented 3 weeks ago

Bug details:

Snippet from referralInvite lambda function

if (action === 'invite') {
      // --- Invitation Creation Logic ---
      const { guest_email, card_image_id} = requestBody;
      // Check if guest_email is already a user
      const userRes = await client.query(
        'SELECT user_id FROM users WHERE email = $1;',
        [guest_email],
    );

    let inviteId;
    let emailParams;
    let userExisted = false;

    if (userRes.rows.length > 0) {
      // a user already exists with the guest_email!
      const userId = userRes.rows[0].user_id;
      userExisted = true;

      // Insert invitation with existing user as guest
      const inviteRes = await client.query(
        'INSERT INTO invitations (guest_email, card, guest, status) VALUES ($1, $2, $3, $4) RETURNING invite_id;',
        [guest_email, card_image_id, userId, 'pending'],
      );
chef-louis commented 3 weeks ago

Another bug:

Image

chef-louis commented 3 weeks ago

Another bug:

Image