Created
October 13, 2022 17:01
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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