rsnext/examples/with-supabase-auth-realtime-db/pages/profile.js
Aryan Beezadhur 8eec49208f
Rename utils to lib (#29651)
Rename all instances of `utils` to `lib` in this example to maintain consistency with other examples.
2021-10-05 20:24:19 +00:00

41 lines
1.2 KiB
JavaScript

import Link from 'next/link'
import { Card, Typography, Space } from '@supabase/ui'
import { supabase } from '../lib/initSupabase'
export default function Profile({ user }) {
return (
<div style={{ maxWidth: '420px', margin: '96px auto' }}>
<Card>
<Space direction="vertical" size={6}>
<Typography.Text>You're signed in</Typography.Text>
<Typography.Text strong>Email: {user.email}</Typography.Text>
<Typography.Text type="success">
User data retrieved server-side (from Cookie in getServerSideProps):
</Typography.Text>
<Typography.Text>
<pre>{JSON.stringify(user, null, 2)}</pre>
</Typography.Text>
<Typography.Text>
<Link href="/">
<a>Static example with useSWR</a>
</Link>
</Typography.Text>
</Space>
</Card>
</div>
)
}
export async function getServerSideProps({ req }) {
const { user } = await supabase.auth.api.getUserByCookie(req)
if (!user) {
// If no user, redirect to index.
return { props: {}, redirect: { destination: '/', permanent: false } }
}
// If there is a user, return it.
return { props: { user } }
}