Remix Auth Socials
Remix Auth Socials is a utility package designed to simplify the integration of multiple OAuth2 social login strategies with `remix-auth`. Instead of managing various social provider strategies internally, it collates and re-exports existing community-developed `remix-auth-*-strategy` packages, providing a unified `SocialsProvider` enum for easier dynamic routing and button rendering. The current stable version is 3.0.0, though the README marks it as 'broken / beta / use at your own risk' due to ongoing updates for Remix Router v7 compatibility and dropping support for some previously included strategies. The release cadence is irregular, largely driven by updates to the underlying community packages it aggregates. Its key differentiator is providing a single point of reference and a consistent enum for managing a suite of social authentication options within a Remix application, aiming to reduce `package.json` bloat from individual strategy installations while centralizing the usage pattern.
Common errors
-
Error: Strategy 'YOUR_PROVIDER_NAME' is not defined. Did you forget to add it to the authenticator?
cause You are attempting to authenticate with a social provider using `params.provider` (e.g., `SocialsProvider.DISCORD`) that has not been added to your `Authenticator` instance via `authenticator.use(new DiscordStrategy(...), SocialsProvider.DISCORD);` in `auth.server.ts`.fixEnsure that every `SocialsProvider` enum value used in your frontend buttons has a corresponding `authenticator.use()` call in your `auth.server.ts` (or equivalent file), properly instantiating the relevant `remix-auth-*-strategy` package. -
Error: Cannot find module 'remix-auth-google' or its corresponding type declarations.
cause You are trying to import a specific social strategy (e.g., `GoogleStrategy`) in your `auth.server.ts` without having installed its dedicated package.fixInstall the required individual strategy package for each social provider you intend to use. For example, for Google, run `npm install remix-auth-google`. Remember that `remix-auth-socials` itself does not bundle these strategies. -
TypeError: (0 , remix_auth_socials__WEBPACK_IMPORTED_MODULE_1__.SocialsProvider) is not a function
cause This error typically occurs when trying to use `SocialsProvider` as if it were a function or class constructor. `SocialsProvider` is an enum (an object with string values), not a callable entity.fixAccess enum members directly, e.g., `SocialsProvider.GOOGLE` or `SocialsProvider.GITHUB`. Ensure you are not trying to instantiate it or call it like `SocialsProvider()`.
Warnings
- breaking Version 3.0.0 of `remix-auth-socials` introduces significant breaking changes by dropping several social authentication strategies (Discord, LinkedIn, X/Twitter) that are incompatible with Remix Router v7. If you relied on these providers, you must either downgrade or find alternative implementations.
- gotcha The package owner states that V3 is 'considered broken / beta / use at your own risk' and that 'Facebook and Google are untested as of yet'. This indicates potential instability and lack of full verification for critical features.
- gotcha Maintenance of `remix-auth-socials` is described as infrequent ('I dont maintain this super often'). This may lead to slower bug fixes, delayed updates for new Remix versions, or lack of support for new social provider features.
- gotcha `remix-auth-socials` primarily acts as a collator and provides the `SocialsProvider` enum. The actual social authentication strategies (e.g., `GoogleStrategy`) are sourced from independent community packages. You must install these individual `remix-auth-*-strategy` packages separately.
Install
-
npm install remix-auth-socials -
yarn add remix-auth-socials -
pnpm add remix-auth-socials
Imports
- SocialsProvider
const SocialsProvider = require('remix-auth-socials').SocialsProvider;import { SocialsProvider } from 'remix-auth-socials';
Quickstart
import { Authenticator } from 'remix-auth';
import { createCookieSessionStorage } from '@remix-run/node';
import { GoogleStrategy } from 'remix-auth-google'; // Install via 'npm install remix-auth-google'
import { Form } from '@remix-run/react';
import { SocialsProvider } from 'remix-auth-socials';
import type { ActionArgs, LoaderArgs } from '@remix-run/node';
// app/server/auth.server.ts
const sessionStorage = createCookieSessionStorage({
cookie: {
name: '__session',
httpOnly: true,
path: '/',
sameSite: 'lax',
secrets: [process.env.SESSION_SECRET ?? 's3cr3t'],
secure: process.env.NODE_ENV === 'production',
},
});
export const authenticator = new Authenticator<string>(sessionStorage);
// Add Google Strategy (example: ensure remix-auth-google is installed)
authenticator.use(
new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID ?? '',
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? '',
callbackURL: 'http://localhost:3000/auth/google/callback',
},
async ({ profile }) => {
// Here you can return the user info from your database or create a new user
return profile.emails[0].value;
}
),
SocialsProvider.GOOGLE // Use the enum for consistency
);
// app/routes/auth/$provider.tsx
export let loader = () => new Response('Login via social provider', { status: 404 });
export let action = ({ request, params }: ActionArgs) => {
if (!params.provider) throw new Response('Provider missing', { status: 400 });
return authenticator.authenticate(params.provider, request);
};
// app/routes/auth/$provider.callback.tsx
export let callbackLoader = ({ request, params }: LoaderArgs) => {
if (!params.provider) throw new Response('Provider missing', { status: 400 });
return authenticator.authenticate(params.provider, request, {
successRedirect: '/dashboard',
failureRedirect: '/login',
});
};
// app/routes/login.tsx
interface SocialButtonProps {
provider: SocialsProvider;
label: string;
}
const SocialButton: React.FC<SocialButtonProps> = ({ provider, label }) => (
<Form action={`/auth/${provider}`} method="post">
<button type="submit">{label}</button>
</Form>
);
export default function Login() {
return (
<div style={{ fontFamily: 'system-ui, sans-serif', lineHeight: '1.8' }}>
<h1>Login</h1>
<SocialButton
provider={SocialsProvider.GOOGLE}
label="Login with Google"
/>
{/* Add other available social buttons here, e.g., GitHub, Facebook */}
<Form action="/logout" method="post">
<button type="submit">Logout</button>
</Form>
</div>
);
}
// app/routes/logout.tsx
export let logoutAction = async ({ request }: ActionArgs) => {
return authenticator.logout(request, { redirectTo: '/login' });
};