Skip to content

Instantly share code, notes, and snippets.

@KevinDanikowski
Created July 27, 2020 18:58
Show Gist options
  • Save KevinDanikowski/162fce7decf4b234c58dee9ec7daed3c to your computer and use it in GitHub Desktop.
Save KevinDanikowski/162fce7decf4b234c58dee9ec7daed3c to your computer and use it in GitHub Desktop.
// PROTECTED PAGE
import React from 'react'
import { Loading } from '../components/QueryHandling'
import { useAuth } from '../lib/UserContext'
export default function ProtectedPage() {
const { user } = useAuth(true)
if (!user) {
return <Loading />
}
return (
<>
...
</>
)
}
// UNPROTECTED PAGE
import React from 'react'
import { useAuth } from '../lib/UserContext'
export default function ProtectedPage() {
const { user } = useAuth(true)
const userEmail = user ? user.signInUserSession.idToken.payload.email : ''
return (
<>
<div>Email: {userEmail}</div>
...
</>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment