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

Google oauth #7

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Google oauth #7

wants to merge 9 commits into from

Conversation

Alankvuong
Copy link
Collaborator

  • Set up Google Authentication for app
  • Show screen when logged in and basic button for signing out

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some high level feedback:

  1. It's not safe to check in to version control client IDs and secrets. Those should be revoked and instead loaded via env vars.
  2. We discussed removing the backend and only having a frontend. How does that fit into this PR?

README.md Outdated
@@ -0,0 +1,45 @@
# CRUD Database App

This code runs the CRUD Database application for volunteers to interact with, input, and update datbase information relating to the Parking Lot Map and Parking Reform Map.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This code runs the CRUD Database application for volunteers to interact with, input, and update datbase information relating to the Parking Lot Map and Parking Reform Map.
This code runs the CRUD Database application for volunteers to interact with, input, and update database information relating to the Parking Lot Map and Parking Reform Map.

@@ -0,0 +1,60 @@
import express, { Express, Request, Response, Application } from 'express';``
// const express = require("express");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When landing a PR, you want to remove all commented out code. It's unclear to future readers why it's there, and over time the code tends to get outdated.

It's a good practice to proactively review your PR before asking for review to look for any problems like this.

import cors from "cors";


// for env file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is already self-documenting. Not necessary

Comment on lines 54 to 59
// // fetch the current session
// const currentSession = supabase.auth.getSession();
// if(currentSession) {
// setSession(currentSession);
// // setUser(currentSession.)
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on removing commented out code.

Comment on lines 14 to 25
const supabaseUrl = process.env.SUPABASE_URL ?? '';
const supabasePublicAnonKey = process.env.SUPABASE_PUBLIC_ANON_KEY ?? '';

console.log(supabaseUrl);

const supabase = createClient(supabaseUrl, supabasePublicAnonKey, {
auth: {
autoRefreshToken: false,
persistSession: true,
detectSessionInUrl: false
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's useful to put this behind a helper function like createSupabase. You don't need to access the variables supabaseUrl and supabasePublicAnonKey elsewhere, so that gives you better scoping and better abstracts the code.

import HomePage from "./pages/home/home"
import { AuthProvider } from "./contexts/AuthContext";

// const HomePage = lazy(() => import("./pages/home/home"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto commented out code

<Suspense fallback={<div>Loading...</div>}>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/logged-in" element={<LoggedIn />} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally the URL wouldn't change when you're logged in to a value like this. Was this for experimentation, or you intend to keep it?

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Alan. I'm getting a blank screen when I run npm start. No error messages in the dev console or terminal. I imagine this is from not setting up env vars? But I'm surprised there aren't errors.

Per our video chat, please remove the crud-frontend/ folder because it's not necessary. Although that change would be even better in a dedicated precursor PR to delete crud-backend and move crud-frontend to be top level.

Comment on lines +5 to +6
const supabase = createClient(process.env.REACT_APP_SUPABASE_URL, process.env.REACT_APP_SUPABASE_PUBLIC_ANON_KEY, {
auth: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add instructions to the README about what env vars are necessary, where to find them, and where to set them like an .env file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this seems to duplicate code from supabaseSetup.tsx?

const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: 'http://localhost:3000/logged-in'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't redirect

<>
<div className="google-login-button">
<div id="g_id_onload"
data-client_id="757897629512-3ltcl0q206uancd3h7jbi63aaj3levud.apps.googleusercontent.com"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally client IDs are risky to leak in source code and should be set via env vars. What is this client ID corresponding to? Google API client ID?

@@ -0,0 +1,76 @@
import React, { useState, useEffect } from "react";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call this login/login.tsx rather than login/index.tsx or simply login.tsx?

Also I believe the convention is to use capital letters for the file name, Login.tsx.

import React, { createContext, useState, useEffect, useContext, ReactNode } from "react";
import { createClient, Session, AuthChangeEvent } from "@supabase/supabase-js";

const supabase = createClient(process.env.REACT_APP_SUPABASE_URL, process.env.REACT_APP_SUPABASE_PUBLIC_ANON_KEY, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated

@@ -7,5 +7,6 @@
<body>
<div id="app"></div>
<script type="module" src="index.tsx"></script>
<script src="https://accounts.google.com/gsi/client" async></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You auto-inject this via the JS code. What approach did you intend to do?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants