User Authentication with Google OAuth 2.0
LaunchFa.st uses in house simple as heck server-side first Google OAuth 2.0 to help you authenticate users via Google.
src/pages/api/auth/google.js
and src/pages/api/auth/callback/google.js
file. src/routes/api/auth/google/+server.ts
and src/routes/api/auth/callback/google/+server.ts
file. - Update the
.env
file or hosting provider’s environment variable to have the necessary variables for Google OAuth 2.0:
# Obtained from Google APIs
# https://developers.google.com/identity/protocols/oauth2/web-server#prerequisites
GOOGLE_AUTH_ID=".....-...........apps.googleusercontent.com"
GOOGLE_AUTH_SECRET=".....-..........-....."
# Based on your domain
GOOGLE_AUTH_CALLBACK_URL="https://your-domain.com/api/auth/callback/google"
- To simply authenticate users via Google, import the
Sign-In-With-Google
component in each framework as described below:
---
// File: src/pages/file.astro
import SignInWithGoogle from '@/components/Sign-In-With-Google.astro'
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
</head>
<body>
<SignInWithGoogle />
</body>
</html>
<script>
// File: src/routes/+page.svelte
import SignInWithGoogle from '@/components/Sign-In-With-Google.svelte'
</script>
<SignInWithGoogle />