Skip to content

Conversation

@ttpss930141011
Copy link

@ttpss930141011 ttpss930141011 commented Mar 1, 2025

Upgrade to Remix Auth v4 for React Router 7

This PR upgrades the LinkedIn strategy to support Remix Auth v4 and React Router 7, bringing major improvements and modern architecture.

Key Changes

  • Rewrote strategy implementation using Arctic OAuth library
  • Updated types to match Remix Auth v4 API
  • Migrated to Bun for testing
  • Improved documentation with detailed examples
  • Added new authors section

API Changes

  • Constructor option names updated:
    • clientIDclientId
    • clientSecret (unchanged)
    • callbackURLredirectURI
    • scopescopes (array or string)
  • Verify callback now receives { profile, tokens, request } object
  • Tokens accessed via methods: tokens.accessToken() and tokens.refreshToken()
  • Session management must be handled manually in callback routes

Migration Example (v2.x to v3.x)

new LinkedInStrategy(
  {
-    clientID: "YOUR_CLIENT_ID",
+    clientId: "YOUR_CLIENT_ID",
-    callbackURL: "https://example.com/callback",
+    redirectURI: "https://example.com/callback",
-    scope: "r_emailaddress r_liteprofile",
+    scopes: "r_emailaddress r_liteprofile",
  },
-  async ({ accessToken, refreshToken, profile }) => {
+  async ({ profile, tokens }) => {
    return {
      ...user,
-     accessToken,
+     accessToken: tokens.accessToken(),
-     refreshToken,
+     refreshToken: tokens.refreshToken ? tokens.refreshToken() : null,
    };
  }
)

Routes must now manually handle session management:

export async function loader({ request }) {
-  return authenticator.authenticate("linkedin", request, {
-    successRedirect: "/dashboard",
-    failureRedirect: "/login",
-  });
+  try {
+    const user = await authenticator.authenticate("linkedin", request);
+    const session = await sessionStorage.getSession(request.headers.get("cookie"));
+    session.set("user", user);
+    const headers = new Headers();
+    headers.append("Set-Cookie", await sessionStorage.commitSession(session));
+    return redirect("/dashboard", { headers });
+  } catch (error) {
+    return redirect("/login?error=auth_failed");
+  }
}

Version Compatibility

  • v3.x → Remix Auth v4.x and React Router 7
  • v2.x → Remix Auth v3.x
  • v1.x → Remix Auth v1.x and v2.x

Issue

#6

…newest remix-auth-strategy-template

- Upgrade to ESM module
- Update package dependencies
- Refactor project structure
- Add new build and quality scripts
- Update Node.js engine requirement to >=20.0.0
- Switch to new authentication library (arctic)
- Add type exports and sideEffects configuration
…y following the newest remix-auth-strategy-template

- Add Biome.json for linting and formatting
- Update ESLint configuration
- Modify TypeScript configuration
- Add TypeDoc configuration
- Create exports validation script
…ion approach

- Migrate from OAuth2Strategy to custom Strategy implementation
- Add comprehensive authentication flow with state management
- Implement token refresh and improved error handling
- Update type definitions and constructor options
- Add debug logging and more robust profile retrieval
- Add console logging for better script visibility and debugging
- Modify entrypoint detection to target 'remix-auth-linkedin'
- Include more informative console output for export problems
- Improve error handling and script flow
- Integrate Arctic's LinkedIn OAuth client for improved authentication
- Simplify token exchange and validation logic
- Add support for generating state and handling OAuth errors
- Update type definitions and method implementations
- Enhance debug logging and error handling
- Migrate from Jest to Bun test framework
- Update fetch mocking to handle dynamic URL inputs
- Enhance scope and state validation tests
- Improve token refresh test with more realistic mock
- Simplify test assertions and error handling checks
- Replace global fetch with more flexible mocking approach
- Implement robust callback route for LinkedIn authentication
- Add comprehensive error handling and parameter validation
- Improve session creation and user authentication flow
- Update token retrieval methods to handle potential undefined tokens
- Enhance redirect logic with detailed error scenarios
- Update package.json to include multiple authors
@ttpss930141011 ttpss930141011 changed the title Upgrade to remix-auth V4 for RR7 Upgrade to Remix Auth v4 for React Router 7 Mar 1, 2025
@ttpss930141011 ttpss930141011 force-pushed the main branch 3 times, most recently from 4505475 to 0ce98d3 Compare March 3, 2025 04:11
- Update GitHub workflows to use Node.js 20
- Replace npm test with bun test in CI pipeline
- Add Bun setup for testing and quality checks
- Update publish workflow with npm pkg fix and automation token
@gielcobben
Copy link

Hello, I wanted to check on the status of this PR. Could you provide an update on when we might expect the merge to be completed? Looking forward to this.

@ttpss930141011
Copy link
Author

ttpss930141011 commented Mar 21, 2025

Hello, I wanted to check on the status of this PR. Could you provide an update on when we might expect the merge to be completed? Looking forward to this.

During the time for waiting review, I've push this version to npm for my personal development work. Welcome to take it a try.

npm i remix-auth-linkedin-next

@gielcobben
Copy link

Thank you! It works like a charm.

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.

2 participants