Amara
03/04/2023, 4:50 PMtinyjetpack
03/04/2023, 5:17 PMJ3ltR
03/04/2023, 5:31 PMgetSession()
from the @supabase/auth-helpers-sveltekit
package. In my project, I have a layout.svelte
where I access the supabase session as follows:
ts
<script lang="ts">
...
import type { LayoutData } from './$types';
export let data: LayoutData;
let session = data.session;
let userId = session?.user.user_metadata.provider_id;
let userAvatar = session?.user.user_metadata.avatar_url;
let userName = session?.user.user_metadata.full_name;
</script>
<div class=wrapper>
<NavigationBar {userId} {userAvatar} {userName} />
<slot />
</div>
This layout uses data from the `layout.ts`:
ts
export const load = (async ({ fetch, data, depends }) => {
...
const supabase = createSupabaseLoadClient<Database>({
...
});
const {
data: { session }
} = await supabase.auth.getSession();
return { supabase, session };
}) satisfies LayoutLoad;
This works fine with a normal page. However, whenever I have a page which makes an API call in a `page.ts`/`page.server.ts` to a server.ts
in which I need a supabase session:
ts
export const GET = (async (event) => {
const session = await event.locals.getSession();
...
the session in the layout.svelte
changes to null
(which makes my navigation bar looks like the user is logged out).
My hooks.server.ts
looks like this:
ts
export const handle = (async ({event, resolve}) => {
event.locals.supabase = createSupabaseServerClient({
...
});
event.locals.getSession = async () => {
const {
data: { session }
} = await event.locals.supabase.auth.getSession();
return session;
};
...
The hooks.server.ts
, layout.ts
and server.ts
code I used are from https://supabase.com/docs/guides/auth/auth-helpers/sveltekit.
Is the other session changing to null
intended behaviour? Any idea how I can solve this issue? Thank you!mikel
03/04/2023, 6:38 PMrobertn702
03/04/2023, 8:55 PMtext[]
, int[]
, etc), I noticed that there aren't any array types provided in the select boxsquallsama
03/04/2023, 9:00 PMjonah
03/04/2023, 9:23 PMajv
03/04/2023, 9:28 PMnateland
03/04/2023, 10:10 PMgerry
03/04/2023, 11:46 PMalana
03/04/2023, 11:52 PMColors
03/05/2023, 1:01 AMFailed to invite user: User not allowed
) or create new buckets(new row violates row-level security policy for table "buckets"
). Also I can't set up auth providers(I only can set up policies).
When I look at the broser console I see this error spammed in the console:
_app-9045f33443b356a2.js:1 GET http://<MyServerIP>:3000/api/profile/permissions 404 (Not Found)
alexanderwford
03/05/2023, 1:13 AMrlee128
03/05/2023, 1:41 AMsalzar
03/05/2023, 2:31 AMconst handleClick = (fileData:string) => {
setChecked((prevState) => !prevState);
const extension = fileData.split('.').pop()?.toLowerCase();
if (extension) {
console.log(extension)
if (!checked) {
addCheckedFile(props.fileData);
} else {
removeCheckedFile(props.fileData);
}
}
};
AlanK
03/05/2023, 4:17 AMimport { invalidate } from '$app/navigation';
import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_SUPABASE_URL } from '$env/static/public';
import { createSupabaseLoadClient } from '@supabase/auth-helpers-sveltekit';
import type { LayoutLoad } from './$types';
import type { Database } from '$lib/db.types';
export const load: LayoutLoad = async ({ fetch, data, depends }) => {
depends('supabase:auth');
const supabase = createSupabaseLoadClient<Database>({
supabaseUrl: PUBLIC_SUPABASE_URL,
supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
event: { fetch },
serverSession: data.session,
onAuthStateChange() {
invalidate('supabase:auth');
}
});
const {
data: { session }
} = await supabase.auth.getSession();
return { supabase, session };
};
The buils fails with a
TypeError Cannot read properties of null (reading 'session')
pointing to
serverSession: data.session
Have I missed something?TheWeakNinja
03/05/2023, 5:14 AM// Subscribe to realtime updates
const messagesSubscription = supabase
.channel(`room:${room_id}`)
.on("postgres_changes", { event: "INSERT", schema: "public", table: "messages" }, (payload) => {
console.log("Received realtime update:", payload);
// Update list of messages
// Ignore TS error from line below because payload isn't typed correctly... ?
// @ts-ignore
setMessages((messages) => [...messages, payload.new]);
// Scroll to bottom
document.getElementById("scroll-to")!.scrollIntoView({ behavior: "smooth" });
})
.subscribe();
I am also very new to TypeScript and Supabase both so if this is a commonly asked question, I apologize!atgctg
03/05/2023, 10:36 AMprovider_token
field from the session for the googleapis
auth.
ts
const client = new google.auth.OAuth2()
client.setCredentials({
access_token: session.provider_token,
})
Problem is that after a while the provider_token
field will be set to null
. How do I prevent that from happening?chrtravels
03/05/2023, 12:30 PMimport Layout from '@/components/layout/Layout';
import '@/styles/globals.css'
import { createBrowserSupabaseClient } from '@supabase/auth-helpers-nextjs'
import { Auth, ThemeSupa } from '@supabase/auth-ui-react'
import { SessionContextProvider, useSession, useSupabaseClient } from '@supabase/auth-helpers-react'
import { useState } from 'react'
// import UserProvider from '../context/userContext'
export default function App({ Component, pageProps }) {
const [supabase] = useState(() => createBrowserSupabaseClient())
const session = useSession()
const supabaseAuthClient= useSupabaseClient()
return (
<SessionContextProvider supabaseClient={supabase} initialSession={pageProps.initialSession}>
{!session ? (
<Auth supabaseClient={supabaseAuthClient} appearance={{ theme: ThemeSupa }} />
) : (
<Layout>
<Component {...pageProps} />
</Layout>
)}
</SessionContextProvider>
)
Any assistance is appreciated. This Supabase auth has been a three day nightmare and hoping to get this sorted.
If I get the login working, I think I can then access my user throughout the rest of the site.mattbcool
03/05/2023, 12:37 PMtommyb10
03/05/2023, 12:49 PMAmr
03/05/2023, 1:02 PMjs
supabase
.from('reservations')
.select(`*,
departure_trip:trips!reservations_departure_trip_fkey(*, repeating_trip:repeating_trips!trips_repeating_trip_fkey(*)),
return_trip:trips!reservations_return_trip_fkey(*, repeating_trip:repeating_trips!trips_repeating_trip_fkey(*)),
room_details:hotel_prices!reservations_room_details_fkey(*, hotel:hotels!hotel_prices_hotel_fkey(*),room:hotel_rooms!hotel_prices_room_fkey(*))`,
{ count: 'exact' })
.or(`departure_trip.id.in.${trimmedTripsIdsString}, return_trip.id.in.${trimmedTripsIdsString}`,
{ foreignTable: 'trips' })
I have an array of trip IDs , say const trimmedTripsIdsString = '(1, 2, 3)'
I want to get all reservations that either subscribed to a departure_trip
with an ID
within that array, or a return_trip
with an ID
within that array.
But that query returns null
!chrtravels
03/05/2023, 1:35 PMexport async function getSessionProfile(userId) {
let { data: profiles, error } = await supabase
.from('profiles')
.select('*')
.where(profiles.id === userId);
return profiles;
}
salzar
03/05/2023, 2:40 PMyngwi
03/05/2023, 2:44 PMjoaquimley
03/05/2023, 3:28 PMsupabase
client, this is running on an express (NestJS) app.
I'm instantiating it as usual:
typescript
import { createClient, SupabaseClient } from '@supabase/supabase-js';
(....)
const client = createClient(SupabaseConfig.url(), SupabaseConfig.anonKey());
And setting the session like so:
typescript
const { data, error } = await client.auth.setSession({
access_token,
refresh_token,
});
If I console.log()
the data
property (after checking if error
is null) it does return a session object including the user info but (and it even refreshes the tokens) but,
If I try to request any data or query any data it just throws an auth error:
typescript
const user = await client.auth.getUser()
Reading the documentation, it seems like this is the proper way to attach a session to a supabase
client, so I don't really get what's happening.
Thanks in advance.darkej
03/05/2023, 3:48 PMjs
import supabase from "@/utils/supabase";
export const revalidate = 0;
async function getEggs() {
const {data, error} = await supabase.from("eggs").select().order("created_at");
if (error) console.error(error);
return data;
}
export default async function Home() {
const eggs = await getEggs();
return (
// render eggs
);
}
There is a second page to get data from user and insert it into supabase:
jsx
"use client";
import {useState} from "react";
import supabase from "@/utils/supabase";
import Link from "next/link";
import {useRouter} from "next/navigation";
export default function Page() {
const [eggName, setEggName] = useState("");
const router = useRouter();
const handleOnChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setEggName(e.target.value);
};
const handleOnClick = async () => {
const {data: egg, error} = await supabase.from("eggs").insert({egg_name: eggName});
if (error) console.error(error);
router.push("/eggs/get");
};
return (
<div>
<input
type="text"
className="w-[10rem] py-3 px-4 block border border-gray-200 rounded-md text-sm focus:border-blue-500 focus:ring-blue-500"
onChange={handleOnChange}
/>
<button onClick={handleOnClick}>submit</button>
</div>
);
}
When user push button:
1. Insert new record into database
2. Redirect to /eggs/get
Now sometimes it’s get fresh data and I am able to see new record but somtimes not - its not rendered.
What is the best approach in Next13js to handle data insertion and immediatly see the changes ?NeoPrint3D
03/05/2023, 4:19 PMyngwi
03/05/2023, 4:21 PMsamuel83
03/05/2023, 4:38 PMFailed to invite user: failed to make invite request: Database error finding user
Does anyone have any idea why this is happening?