- 🔐 Google OAuth Authentication (fully implemented)
- 🖼️ Beautiful Success & Error Pages
- 🔄 Enhanced Profile Data with Avatar Display
- 📱 Mobile-Friendly Interface
- 🛡️ TypeScript Support
- 🐳 Docker Test Environment Included
The plugin comes with a complete test environment using Docker Compose, which includes:
- Medusa backend with the auth plugin pre-configured
- Admin dashboard
- PostgreSQL database
- Redis for caching
# Clone the repository (if not already done)
git clone <repository-url>
cd medusa-plugin-auth-v2
# Start the Docker environment
docker-compose up -d
Access the services:
- Medusa Backend: http://localhost:9000
- Medusa Admin: http://localhost:7001
- Authentication URLs:
- Start Google OAuth: http://localhost:9000/store/auth/google
- Success Page: http://localhost:9000/auth/success
- Error Page: http://localhost:9000/auth/error
- Configure your OAuth credentials in a
.env
file (see.env-example
) - Restart the Docker containers to apply the changes
- Navigate to http://localhost:9000/store/auth/google to start the OAuth flow
- After successful authentication, you'll be redirected to the success page
npm install medusa-plugin-auth-v2
# or
yarn add medusa-plugin-auth-v2
Add the plugin to your medusa-config.js
or medusa-config.ts
:
const { defineConfig } = require('@medusajs/medusa')
module.exports = defineConfig({
plugins: [
// ... other plugins
{
resolve: "medusa-plugin-auth-v2",
options: {
// JWT settings
jwt: {
secret: process.env.JWT_SECRET,
expiresIn: "7d"
},
// Cookie settings
cookie: {
name: "medusa-auth",
secure: process.env.NODE_ENV === "production",
maxAge: 1000 * 60 * 60 * 24 * 7 // 7 days
},
// OAuth provider configurations
google: {
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL,
// Strategy options
strategyOptions: {
scope: ["profile", "email"]
}
}
}
}
]
})
The plugin provides these endpoints:
Endpoint | Method | Description |
---|---|---|
/store/auth/google |
GET/POST | Starts Google OAuth flow |
/store/auth/google/callback |
GET | Google OAuth callback handler |
/auth/success |
GET | Success page with user profile information |
/auth/error |
GET | Error page with detailed error information |
If you're migrating from the v1 version of the plugin, please see our detailed Migration Guide.
- File-based Routes: Routes now use Medusa v2's file-based routing system
- Function-based Subscribers: Subscribers now use functions instead of classes
- Container API Changes: Container registration and resolution patterns have changed
- New Success/Error Pages: Enhanced pages with user details and error information
- Enhanced Profile Data: Better handling of user profile information
- Profile Picture Not Displaying: Add
referrerpolicy="no-referrer"
to image tags for Google profile pictures - "resolver.resolve is not a function": This indicates a container resolution issue in Medusa v2
- Authentication Flow Starts But Never Completes: Check that your callback URLs are correctly configured
- Port Conflicts: If ports 9000 or 7001 are already in use, modify the
docker-compose.yml
file - Environment Variables: Ensure all required variables are set in your
.env
file - Container Rebuilding: Use
docker-compose up -d --build
to rebuild containers after code changes
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
MIT License (C) 2025 Paul Pierre