Skip to content

Instantly share code, notes, and snippets.

@asunar
Created October 13, 2022 17:01
Show Gist options
  • Save asunar/9ea720051109fcc1ad3f15923b856926 to your computer and use it in GitHub Desktop.
Save asunar/9ea720051109fcc1ad3f15923b856926 to your computer and use it in GitHub Desktop.
architect project Index.js file that redirects to google login if user is not logged in. (Using Auth0 with google sign in)
const layout = require('@architect/shared/layout')
const arc = require('@architect/functions')
exports.handler = arc.http.async(handler)
// @ts-ignore
async function handler(req) {
const isLoggedIn = !!req.session.email
if(isLoggedIn) {
return {
location: "/foods"
}
}
const {
BASE_URL: baseUrl,
AUTH0_ISSUER_BASE_URL: auth0IssuerBaseUrl,
AUTH0_CLIENT_ID: auth0clientId
} = process.env
const auth0LoginUrl=`${auth0IssuerBaseUrl}/authorize?response_type=code&client_id=${auth0clientId}&redirect_uri=${baseUrl}/callback&scope=openid%20profile%20email`
var contents = `
<section class="hero">
<h1>Welcome to Pantry Hopper!</h1>
<h3>Login with your Google account to get started.</h3>
<div class="col-md-3 text-end">
<a href="${auth0LoginUrl}" class="btn btn-primary" style="float: left">Login with Google</a>
</div>
</hero>
`
return {
html: layout({contents, req })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment