Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

[FEATURE] A question submission box (backend) #108

Closed
ykdojo opened this issue Aug 20, 2022 · 29 comments · Fixed by #187
Closed

[FEATURE] A question submission box (backend) #108

ykdojo opened this issue Aug 20, 2022 · 29 comments · Fixed by #187
Labels
feat New feature addition or request

Comments

@ykdojo
Copy link
Collaborator

ykdojo commented Aug 20, 2022

Description

This is the backend portion of #59.

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 20, 2022

The first step for this task: design the database schema.

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 20, 2022

I'm going to start working on this one soon.

@ykdojo ykdojo self-assigned this Aug 20, 2022
@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 20, 2022

Users table:

Image

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 21, 2022

I'm going to un-assign myself since I'll be away - in case anyone else wants to take it. I'll assign myself when I start working on it again.

@ykdojo ykdojo removed their assignment Aug 21, 2022
@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 21, 2022

From my own comment on #59:

The required fields:

  • Company (FAANG+, or a custom textbox)
  • Position
  • Location
  • Date (how long ago was this asked?)
  • Question (100 char max?)
  • Question details
  • Stay anonymous (checkbox)

@ykdojo ykdojo self-assigned this Aug 21, 2022
@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 21, 2022

For the question table, this setup should be replicated:

image

created_by is a foreign key to the auth.users table.

image

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 22, 2022

A rough plan for this feature:

  • Assumption: a user is already logged in
  • Frontend: the user submits a question
  • It goes to an API function within Next.js / Vercel
  • We verify that the user is logged in there (pass a JWT there)
  • It then calls Supabase with admin access
  • The question is inserted in the table.

This whole process may seem a bit complicated, but I think this is the right way to do it to make it as secure as possible.

I've even thought about switching to Firebase because it's complicated, but the workflow with it would be essentially the same.

There may be other ways of going about it (e.g., using row level security / RLS), but the above approach should be the simplest one. I'll document everything as I go here.

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 22, 2022

Documentation references:

(Extra - thinking of sending a PR to update the Supabase doc here once I'm done with this whole process)

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 23, 2022

I did some more research on this.

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 23, 2022

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 23, 2022

update: verified that supabase.auth.session().access_token worked for getting the JWT.

next step: set up a Next.js API and send it there.

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 23, 2022

note: the current user can be retrieved with supabase.auth.user()

@ykdojo ykdojo removed their assignment Aug 24, 2022
@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 24, 2022

I'm going to unassign myself for now to work on #122 first.

@iShibi
Copy link
Contributor

iShibi commented Aug 24, 2022

I can pick the work from here

@iShibi iShibi assigned ykdojo and iShibi and unassigned ykdojo Aug 24, 2022
@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 24, 2022

@iShibi sure! That'd be great.

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 25, 2022

Note: we should add a position field to the table.

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 26, 2022

@iShibi any progress? If not, I was thinking of working on this one

@iShibi
Copy link
Contributor

iShibi commented Aug 26, 2022

Didn't get time to start the work, you can take it @ykdojo

@iShibi iShibi removed their assignment Aug 26, 2022
@ykdojo ykdojo removed their assignment Aug 26, 2022
@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 26, 2022

I'll let you know if/when I start working on it

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 26, 2022

updated schema:

Image

@ykdojo ykdojo self-assigned this Aug 27, 2022
@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 27, 2022

reference: supabase insert

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 28, 2022

note on supabase service role: supabase/supabase#1284

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 28, 2022

After some more digging, I found that Supabase has a Next.js auth component - I'll look into this one next: https://github.com/supabase/auth-helpers/blob/main/packages/nextjs/README.md

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 28, 2022

I thought this might work, but it doesn't quite work the way it's described in the doc.

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 28, 2022

This one worked!

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 28, 2022

Note: I'm currently checking this example to see how they solved it.

@ykdojo
Copy link
Collaborator Author

ykdojo commented Aug 28, 2022

I've found this comment to be helpful, too.

@subhoghoshX
Copy link
Collaborator

subhoghoshX commented Aug 29, 2022

I wrote an SQL query to generate the above table automatically if anyone here doesn't want to do it manually every time. Just go to the SQL Editor tab in supabase and run the query.

If you find any mistake in the query below, please let me know.

-- Create a table for Public Questions
create table questions (
  id bigint generated by default as identity primary key,
  created_at timestamp with time zone default timezone('utc'::text, now()) not null,
  created_by uuid references auth.users(id) not null,
  company text,
  location text,
  asked_date date,
  question text,
  question_details text,
  stay_anonymous boolean,
  is_approved boolean,
  position text
);

@iShibi iShibi changed the title [FEATURE] <A question submission box> (backend) [FEATURE] A question submission box (backend) Sep 5, 2022
@iShibi iShibi added the feat New feature addition or request label Sep 5, 2022
@ykdojo
Copy link
Collaborator Author

ykdojo commented Sep 11, 2022

update: I'll be working off of this draft PR

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat New feature addition or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants