kavla
05/21/2022, 9:43 PMRedHandedBand
05/22/2022, 2:38 AMgaryaustin
05/22/2022, 2:50 AMPsymin
05/24/2022, 3:02 AMAlabhya
05/24/2022, 8:35 AMPsymin
05/24/2022, 8:36 AMBryson_W
05/24/2022, 11:29 PMgaryaustin
05/24/2022, 11:39 PMandriusmv
05/26/2022, 2:10 AMgaryaustin
05/26/2022, 2:15 AMkoho
05/26/2022, 7:21 AMomri
05/27/2022, 2:11 AMts
export async function signInWithAuthTokens({
accessToken,
refreshToken,
}: {
accessToken: string;
refreshToken: string;
}) {
supabase.auth.setAuth(accessToken);
const { session, error } = await supabase.auth.setSession(refreshToken);
if (error != null) {
return { user: null, error };
}
// TODO: maybe figure out a nicer way to do this?
if (session?.user == null) {
return {
user: null,
error: { message: 'session.user is not defined', status: 1337 },
};
}
return { user: session.user!, error: null };
}
i might prepare a small example and put it on github for other people who want to do social auth with supabase in a browser extension.omri
05/27/2022, 2:17 AMsupabase.auth.getSessionFromUrl
be able to receive a url as a parameter for scenarios where one doesn't want to do the whole url parsing dance but doesn't necessarily have a global window.location.href
?
or is there anything else that does this? i couldn't find anything and it's a bit annoying having to reinvent the wheel and (probably, possibly, maybe) face bugs that i really shouldn't have to deal with imo.Torwent
05/28/2022, 1:57 PMjavascript
const supabase = require("@supabase/supabase-js").createClient(
SUPABASE_URL,
SUPABASE_ANON_KEY
)
const run = async (file) => {
let f = require("fs").readFileSync(file)
let fullFinalPath = "test/" + require("path").basename(file)
console.log("Full final path: ", fullFinalPath)
//const { loginError } = await supabase.auth.signIn({
// email: USER,
// password: PASSWORD,
//})
const { uploadError } = await supabase.storage
.from("test")
.upload(fullFinalPath, f)
if (uploadError) {
console.log(uploadError)
} else {
console.log(file, " uploaded.")
}
}
run(process.cwd() + "/test.txt")
Basically this is a simplified version of a github action I made for myself:
https://github.com/Torwent/supabase-upload
It was working fine for a long time but suddenly stopped working and I have no idea why... I haven't changed policies in my buckets, and the code didn't change either until today that I started running tests to see if I could find out what was going on.
I tried both logged in as a user and without, none work.
I've even tried making a brand new bucket but it just won't work... what could it be that I'm doing wrong?Torwent
05/28/2022, 1:58 PMTorwent
05/28/2022, 5:17 PMjaitaiwan
05/30/2022, 5:56 AMjaitaiwan
05/30/2022, 5:57 AM.or
function is supposed to work?nitehawk
05/30/2022, 12:34 PMor
Fainaru
06/02/2022, 3:23 AMsirius
06/02/2022, 11:50 AMimport { NextApiRequest, NextApiResponse } from "next";
import { supabase } from "@/utils/supabaseClient";
const handler = (req: NextApiRequest, res: NextApiResponse) => {
supabase.auth.api.setAuthCookie(req, res);
};
export default handler;
Then I have a listener that calls this endpoint on every client side supabase auth change
import { useEffect, useState, createContext, useContext } from 'react';
import { Session } from '@supabase/supabase-js';
import { supabase } from '@/utils/supabaseClient';
export const UserContext = createContext(null);
export function UserContextProvider(props: any) {
const [session, setSession] = useState<Session | null>(null);
useEffect(() => {
const session = supabase.auth.session();
setSession(session);
const { data: authListener } = supabase.auth.onAuthStateChange(async (event, session) => {
setSession(session);
await fetch('/api/auth', {
method: 'POST',
body: JSON.stringify({ event, session }),
headers: {
'Content-Type': 'application/json',
},
});
});
return () => {
authListener?.unsubscribe();
};
}, []);
const value = {
session,
};
return <UserContext.Provider value={value} {...props} />;
}
export function useSession() {
const context = useContext(UserContext);
return context;
}
Now I would expect that I can just query Supabase normally in all my API routes. However, that's not the case. If I do that it treats queries like those from unauthenticated users.
If I add those lines to my API handler everything works as expected:
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const { token } = await supabase.auth.api.getUserByCookie(req);
supabase.auth.setAuth(token ?? '');
// ...
Why do I need this and is there a way to get rid of it?Steve
06/02/2022, 7:19 PMda newb
06/02/2022, 7:50 PMconst res = await supabaseClient.auth.api.signInWithEmail(email, password)
if (res.data === null) {
throw new Error('data is null')
}
if (res.error !== null) {
throw res.error
}
jwt == res.data.access_token
supabaseClient.auth.setAuth(res.data.access_token)
const {error: signOutError} = await supabaseClient.auth.api.signOut(jwt)
expect(signOutError).toBeNull()
I get a problem with `signOutError`:
expect(received).toBeNull()
Received: {"message": "Invalid token: token contains an invalid number of segments", "status": 401}
What is going on here? I would expect to be able to the access_token
on the session to log out. I did inspect the JWT and it is valid when signed with the default localhost secret: "super-secret-jwt-token-with-at-least-32-characters-long"
da newb
06/02/2022, 7:52 PMconst authSession = supabaseClient.auth.setAuth(res.data.access_token)
jwt = authSession.access_token
then I think it worksda newb
06/02/2022, 7:54 PMjwt == res.data.access_token
instead of jwt = res.data.access_token
... d'oh! sorry for spampaulbrie
06/03/2022, 6:05 PMpaulbrie
06/03/2022, 6:05 PMfranfernandez
06/03/2022, 10:08 PMsupabase.auth.onAuthStateChange((event, session)
is called twice with the event SIGNED_IN
.
There is some way to avoid or distingue between btoh calls ??