{JSON.stringify(data, null, 2)}
+ {JSON.stringify(user, null, 2)}
+ >
+ )
+}
+
+export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
+ // Create authenticated Supabase Client
+ const supabase = createServerSupabaseClient(ctx)
+ // Check if we have a session
+ const {
+ data: { session },
+ } = await supabase.auth.getSession()
+
+ if (!session)
+ return {
+ redirect: {
+ destination: '/',
+ permanent: false,
+ },
+ }
+
+ // Run queries with RLS on the server
+ const { data } = await supabase.from('users').select('*')
+
+ return {
+ props: {
+ initialSession: session,
+ user: session.user,
+ data: data ?? [],
+ },
+ }
+}
+```
+
+Data fetched with provider token:
+{JSON.stringify(allRepos, null, 2)}
+ user:
+{JSON.stringify(user, null, 2)}
+ >
+ )
+}
+
+export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
+ // Create authenticated Supabase Client
+ const supabase = createServerSupabaseClient(ctx)
+ // Check if we have a session
+ const {
+ data: { session },
+ } = await supabase.auth.getSession()
+
+ if (!session)
+ return {
+ redirect: {
+ destination: '/',
+ permanent: false,
+ },
+ }
+
+ // Retrieve provider_token & logged in user's third-party id from metadata
+ const { provider_token, user } = session
+ const userId = user.user_metadata.user_name
+
+ const allRepos = await (
+ await fetch(`https://api.github.com/search/repositories?q=user:${userId}`, {
+ method: 'GET',
+ headers: {
+ Authorization: `token ${provider_token}`,
+ },
+ })
+ ).json()
+
+ return { props: { user, allRepos } }
+}
+```
+
+{JSON.stringify(user, null, 2)}
+}
+
+export const getServerSideProps = withPageAuth({ redirectTo: '/' })
+```
+
+{JSON.stringify(user, null, 2)}
+}
+
+export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
+ // Create authenticated Supabase Client
+ const supabase = createServerSupabaseClient(ctx)
+ // Check if we have a session
+ const {
+ data: { session },
+ } = await supabase.auth.getSession()
+
+ if (!session)
+ return {
+ redirect: {
+ destination: '/',
+ permanent: false,
+ },
+ }
+
+ return {
+ props: {
+ initialSession: session,
+ user: session.user,
+ },
+ }
}
```
-It is also possible to add finer granularity based on the user logged in. I.e. you can specify a promise to determine if a specific user has permission or not.
+