f62cdfe00e
<img width="568" height="513" alt="CleanShot 2025-12-05 at 14 27 16" src="https://github.com/user-attachments/assets/1f44d8b9-8791-4b44-96d5-4a0960a1ab36" /> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds Google OAuth login and a cookie-based “last used” indicator on the login page, with supporting backend, routes, and schema updates. > > - **Auth/Backend**: > - **Google OAuth**: Integrates `remix-auth-google` via new `addGoogleStrategy` and enables when `AUTH_GOOGLE_CLIENT_ID/SECRET` are set (`services/googleAuth.server.ts`, `services/auth.server.ts`). > - **User handling**: Implements `findOrCreateGoogleUser` with linking/upsert logic and conflict logging (`models/user.server.ts`). > - **MFA + session**: Google/GitHub/Magic callbacks now set session, handle MFA, and set a "last-auth-method" cookie (`routes/auth.google*.tsx`, `routes/auth.github.callback.tsx`, `routes/magic.tsx`, `services/lastAuthMethod.server.ts`). > - **GitHub strategy**: Safer email check (`services/gitHubAuth.server.ts`). > - **Routes/UI**: > - **Login page**: Adds "Continue with Google" button and animated "Last used" badge based on cookie; keeps GitHub/Email options (`routes/login._index/route.tsx`). > - **Redirect safety**: Sanitize redirect paths and persist redirect via cookies in auth actions (`routes/auth.github.ts`, `routes/auth.google.ts`). > - **Assets**: Adds `GoogleLogo` SVG. > - **Avatar**: Set `referrerPolicy="no-referrer"` on profile image. > - **Config/Schema**: > - **Env**: Adds `AUTH_GOOGLE_CLIENT_ID`/`AUTH_GOOGLE_CLIENT_SECRET` (`env.server.ts`). > - **DB**: Extends `AuthenticationMethod` enum with `GOOGLE` (Prisma schema + migration). > - **Dependencies**: > - Adds `remix-auth-google` in `package.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 9f84f974bd6f21f1699c4f69a6aa91616842d1b1. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: James Ritchie <james@trigger.dev>
26 lines
865 B
TypeScript
26 lines
865 B
TypeScript
import { createCookie } from "@remix-run/node";
|
|
import { env } from "~/env.server";
|
|
|
|
export type LastAuthMethod = "github" | "google" | "email";
|
|
|
|
// Cookie that persists for 1 year to remember the user's last login method
|
|
export const lastAuthMethodCookie = createCookie("last-auth-method", {
|
|
maxAge: 60 * 60 * 24 * 365, // 1 year
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
secure: env.NODE_ENV === "production",
|
|
});
|
|
|
|
export async function getLastAuthMethod(request: Request): Promise<LastAuthMethod | null> {
|
|
const cookie = request.headers.get("Cookie");
|
|
const value = await lastAuthMethodCookie.parse(cookie);
|
|
if (value === "github" || value === "google" || value === "email") {
|
|
return value;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export async function setLastAuthMethodHeader(method: LastAuthMethod): Promise<string> {
|
|
return lastAuthMethodCookie.serialize(method);
|
|
}
|