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>
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { Authenticator } from "remix-auth";
|
|
import type { AuthUser } from "./authUser";
|
|
import { addEmailLinkStrategy } from "./emailAuth.server";
|
|
import { addGitHubStrategy } from "./gitHubAuth.server";
|
|
import { addGoogleStrategy } from "./googleAuth.server";
|
|
import { sessionStorage } from "./sessionStorage.server";
|
|
import { env } from "~/env.server";
|
|
|
|
// Create an instance of the authenticator, pass a generic with what
|
|
// strategies will return and will store in the session
|
|
const authenticator = new Authenticator<AuthUser>(sessionStorage);
|
|
|
|
const isGithubAuthSupported =
|
|
typeof env.AUTH_GITHUB_CLIENT_ID === "string" &&
|
|
typeof env.AUTH_GITHUB_CLIENT_SECRET === "string";
|
|
|
|
const isGoogleAuthSupported =
|
|
typeof env.AUTH_GOOGLE_CLIENT_ID === "string" &&
|
|
typeof env.AUTH_GOOGLE_CLIENT_SECRET === "string";
|
|
|
|
if (env.AUTH_GITHUB_CLIENT_ID && env.AUTH_GITHUB_CLIENT_SECRET) {
|
|
addGitHubStrategy(authenticator, env.AUTH_GITHUB_CLIENT_ID, env.AUTH_GITHUB_CLIENT_SECRET);
|
|
}
|
|
|
|
if (env.AUTH_GOOGLE_CLIENT_ID && env.AUTH_GOOGLE_CLIENT_SECRET) {
|
|
addGoogleStrategy(authenticator, env.AUTH_GOOGLE_CLIENT_ID, env.AUTH_GOOGLE_CLIENT_SECRET);
|
|
}
|
|
|
|
addEmailLinkStrategy(authenticator);
|
|
|
|
export { authenticator, isGithubAuthSupported, isGoogleAuthSupported };
|