@meridianjs/google-oauth
v0.1.2
Published
Google OAuth 2.0 sign-in module for Meridian
Readme
@meridianjs/google-oauth
Google OAuth 2.0 module for MeridianJS. Adds GET /auth/google and GET /auth/google/callback routes that authenticate users via Google, then issue a MeridianJS JWT.
Installation
npm install @meridianjs/google-oauthConfiguration
// meridian.config.ts
export default defineConfig({
modules: [
{
resolve: "@meridianjs/google-oauth",
options: {
clientId: process.env.GOOGLE_CLIENT_ID ?? "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "",
callbackUrl: process.env.GOOGLE_REDIRECT_URI ?? "",
frontendUrl: process.env.APP_URL,
},
},
],
})Add to your .env:
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=http://localhost:9000/auth/google/callback
APP_URL=http://localhost:5174GOOGLE_REDIRECT_URI must also be registered as an Authorised redirect URI in the Google Cloud Console for your OAuth 2.0 client.
How It Works
- User visits
GET /auth/google→ redirected to Google consent screen. - After consent, Google redirects to
GOOGLE_REDIRECT_URI. - The framework exchanges the code for a Google profile.
- If a user with the matching Google ID exists, they are logged in. Otherwise, a new account is created using the Google profile data.
- If the callback URL included an
invitequery parameter, the user is automatically added to the invited workspace. - A MeridianJS JWT is issued and the user is redirected to
APP_URLwith the token in the query string.
Production
In production, update your .env with the public URLs:
GOOGLE_REDIRECT_URI=https://api.yourdomain.com/auth/google/callback
APP_URL=https://app.yourdomain.comAnd update the authorised redirect URIs in the Google Cloud Console to match.
License
MIT
