Skip to content

Conversation

@Pranav-Batra
Copy link
Contributor

@Pranav-Batra Pranav-Batra commented Dec 2, 2025

Summary

Incorporated authentication with better-auth

Changes

  • Implemented google sign on using better-auth and next.js api handler
  • Added better-auth specific tables to database(session, verification, account, and edited users table)
  • Altered sidebar to reflect a user being logged in or not -> shows sign in button if no session is active, shows logged in user and PFP is session is active
  • added sign-out functionality

Important - Local Replication

  • create .env file in root directory AND apps/next directory with appropriate google keys, db url, and better-auth secret
  • In packages/db, run npx drizzle-kit generate --config "path to drizzle.config.ts"
  • run docker exec -it "container name" psql -U admin -d zotmeal
  • execute the following statements
  • ALTER TABLE "users" ADD COLUMN IF NOT EXISTS "email" text;
  • ALTER TABLE "users" ADD COLUMN IF NOT EXISTS "emailVerified" boolean DEFAULT false;
  • ALTER TABLE "users" ADD COLUMN IF NOT EXISTS "image" text;
  • UPDATE "users" SET "email" = '' WHERE "email" IS NULL;
  • ALTER TABLE "users" ALTER COLUMN "email" SET NOT NULL;
  • ALTER TABLE "users" ADD CONSTRAINT "users_email_unique" UNIQUE("email");
  • UPDATE "users" SET "emailVerified" = false WHERE "emailVerified" IS NULL;
  • ALTER TABLE "users" ALTER COLUMN "emailVerified" SET NOT NULL;
  • in packages/db, run npx drizzle-kit migrate

Closes #519

@Pranav-Batra Pranav-Batra linked an issue Dec 2, 2025 that may be closed by this pull request
@EightBitByte EightBitByte changed the base branch from main to staging December 3, 2025 00:25
Copy link
Collaborator

@LexTruong LexTruong left a comment

Choose a reason for hiding this comment

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

Played around with your changes and everything is functional! Before we pull into dev though, please remove any unnecessary comments, console.log()'s, whitespace, and imports.


const createContext = (
_opts: CreateAWSLambdaContextOptions<APIGatewayProxyEventV2>,
opts: CreateAWSLambdaContextOptions<APIGatewayProxyEventV2>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can remove opts since it's not being used.

Comment on lines 79 to 83
// Pass through to tRPC handler
const trpcHandler = awsLambdaRequestHandler({
router: appRouter,
createContext,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be moved outside the handler function definition.

createContext,
});

return trpcHandler(event);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return trpcHandler(event);
return trpcHandler(event, {} as any);

Quick fix to get rid of the warning about the context argument missing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This file can be deleted after confirming it works.

Comment on lines 1 to 3
/* FOR THIS FILE TO WORK, YOU MUST INCLUDE A .ENV FILE IN THE apps/next DIRECTORY
YOU CAN COPY THE ROOT .ENV FILE WITH DATABASE_URL, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, & BETTER_AUTH_SECRET AND PASTE IT IN apps/next
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

We will incorporate this into our documentation in a separate issue, so this can be removed.


// if (!process.env.DATABASE_URL) throw new Error("DATABASE_URL is not set");

console.log("db/src/index.ts: DATABASE_URL:", process.env.DATABASE_URL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove!

@LexTruong LexTruong self-requested a review December 5, 2025 01:38
Copy link
Collaborator

@LexTruong LexTruong left a comment

Choose a reason for hiding this comment

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

A few more tidying tasks. You can approve the suggestions if you'd like.

Comment on lines 12 to 13
// console.log("Starting sign in...");
// console.log("Base URL:", process.env.NEXT_PUBLIC_BASE_URL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// console.log("Starting sign in...");
// console.log("Base URL:", process.env.NEXT_PUBLIC_BASE_URL);

@@ -1,13 +1,14 @@
import {
awsLambdaRequestHandler,
CreateAWSLambdaContextOptions,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
CreateAWSLambdaContextOptions,

Comment on lines 50 to 52

// Pass through to tRPC handler

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Pass through to tRPC handler

Comment on lines 8 to 11




Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

Comment on lines 16 to 17

// console.log("DATABASE_URL:", process.env.DATABASE_URL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// console.log("DATABASE_URL:", process.env.DATABASE_URL);

if (!process.env.DATABASE_URL) throw new Error("DATABASE_URL is not set");

console.log("drizzle.config.ts: DATABASE_URL:", process.env.DATABASE_URL);
// console.log("drizzle.config.ts: DATABASE_URL:", process.env.DATABASE_URL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// console.log("drizzle.config.ts: DATABASE_URL:", process.env.DATABASE_URL);

Copy link
Collaborator

@LexTruong LexTruong left a comment

Choose a reason for hiding this comment

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

You accidentally deleted the export for the trpc handler, so I had to add it back. Otherwise LGTM!

fix(frontend): sign in button at bottom of sidebar
@LexTruong LexTruong merged commit a5de5af into dev Dec 6, 2025
1 check failed
@LexTruong LexTruong deleted the google-auth branch December 6, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🛡️ User Authentication

4 participants