Closed qisforq closed 2 weeks 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.
@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
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:
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)
);
shared_cards
table and trigger an email to the recipient. For sending emails, you can use AWS Simple Email Service (SES) directly or continue with Strapi if it's already integrated for other purposes.shared_cards
table if the sharer revokes access.When a card is shared:
shared_cards
when access is revoked.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.
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
Backend - Hector / Paula (emails) / Louis Database - Quentin / Hector Frontend - Paula / Hector
Bug details:
dev
and prod
cognito instances hooked up to the same postgres database, it is possible to have multiple users with the same email address. Also there does seem to be an unknown bug where sometimes a user's details are input into the users
table twice (this bug has not yet been fully fleshed out).users
database.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'],
);
Another bug:
Another bug:
pending
state and proceeds to accepted
as expected for the normal flow.
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: