https://supabase.com/ logo
Join Discord
Powered by
# javascript
  • p

    PhantomCode

    03/02/2022, 7:53 AM
    Hey there! 👋 I just started with Supabase as a Frontend Dev and I really like it as BaaS. I try to get a big picture over all the authentication methods and got questions. Currently, I'm building an app where users should sign up & sign up only via email and password. I've a
    posts
    table where RLS is enabled without policies. I'd like to handle all the authorization logic in my servless backend with NextJS. Now, I have an endpoint
    /create-post
    . Only administrators should be able to create a post. Therefore I implemented the following logic. Let's assume a user with the role
    administrator
    is logged in. As far as I realized, the session is stored in local storage. 1. Question: to make a
    POST
    request to the endpoint, I need to send the JWT with the request, because on my server, I do not have access to it via cookies right?
    Copy code
    ts
          await axios.post('/api/create-post', {
            headers: {
              authorization: session?.access_token || '',
            },
            body: ...
          })
    2. Question: the
    session
    object comes from
    supabase.auth.session()
    where I can take the access token. Is this a good practice to call that function or is it redundant to
    supabase.auth.user()
    ? 3. Question: In my serverless function, I want to fetch the user from Supabase via
    const { user } = await supabase.auth.api.getUser(req.headers.authorization)
    . I saw in a video that this step is necessary to establish a session:
    supabase.auth.session = () => ({ access_token: req.headers.authorization })
    but it is hacky and not TS conform. Is the alternative and better solution to use the
    service_role
    key due to the fact that this is not exposed to the public anyways? I'm very grateful for answers, thanks guys!
  • i

    irrationaljared

    03/02/2022, 2:06 PM
    I'm trying to do a very simple workflow with magic links: 1) User requests a magic link: let { user, error } = await supabaseClient.auth.signIn({ email: email }) 2) User receives email and clicks link. After authentication user is redirected to our site. 3) Try to get user on the client using: supabaseClient.auth.user() But no user is returned (it's null). What am I doing wrong?
    g
    d
    • 3
    • 5
  • g

    garyaustin

    03/02/2022, 2:44 PM
    magic link redirect, no user
  • j

    Jaeden

    03/02/2022, 3:25 PM
    can I use this server side? https://supabase.com/docs/reference/javascript/storage-from-upload#upload-file I'm getting a constraint error in the
    owner
    column.
    g
    • 2
    • 3
  • g

    garyaustin

    03/02/2022, 4:09 PM
    upload from server
  • v

    Vanege

    03/03/2022, 1:41 PM
    getting data from two tables that are not directly linked by a foreign key
    • 1
    • 1
  • a

    astronautical

    03/03/2022, 1:47 PM
    I have data from an API being mapped in my frontend. These objects have individual keys/ids. On my database, I have data that needs to be mapped and shown next to the relevant objects. How would I do that? Feel free to answer in the thread.
    g
    • 2
    • 3
  • t

    tandyman

    03/04/2022, 1:41 AM
    Hi Guys! Question....let's say I am trying to do an insert, and I want to also insert a new foreign key row at the same time....is that common/possible/desirable? Example: Add a new restaurant name, and a category for that restaurant, that doesn't yet exist. I'm trying to do it this way, and it fails:
    Copy code
    const { data, error } = await supabase
          .from('restaurants')
          .insert([
            { name: val,
              restaurant_categories: {
                category: newCategory
              }
            },
          ],
          { upsert: true })
  • t

    tandyman

    03/04/2022, 1:41 AM
    I'm probably going about it the wrong way, so I'm looking for whatever the correct/best practice is.
  • t

    tandyman

    03/04/2022, 1:42 AM
    How can I insert a new restaurant, belonging to a new category, in one insert? Or should I expect to be able to do that?
  • g

    garyaustin

    03/04/2022, 1:56 AM
    You will need to run two inserts or use an rpc call and function with two sql inserts. The call will be run as a transaction so both inserts need to succeed for success which is usually what you want.
  • t

    tandyman

    03/04/2022, 2:20 AM
    Ok, cool, thanks!
  • t

    tandyman

    03/04/2022, 2:20 AM
    Appreciate the quick reply.
  • t

    tandyman

    03/04/2022, 2:23 AM
    Man, that can get pretty intense if there is data being added to like 5 or 6 tables at one time.
    g
    • 2
    • 1
  • g

    garyaustin

    03/04/2022, 2:39 AM
    update mutliple tables
  • p

    PhantomCode

    03/04/2022, 7:49 AM
    ping!
    • 1
    • 1
  • r

    risingryzen

    03/06/2022, 3:04 AM
    Anyone know any good React components/libraries that for editors (Markdown)? I'm looking for an editor similar to that of Stackoverflow.com or Github.com.
  • r

    risingryzen

    03/06/2022, 5:40 AM
    Did some digging and found this in case anyone else finds it useful, found this https://github.com/JefMari/awesome-wysiwyg/blob/master/readme.md#for-react
  • h

    hotbelgo

    03/06/2022, 7:01 AM
    Looking for some advice. I'm using Google Signin. At the moment of signin I require users to provide one piece of information. Once signin is complete I want to have access to the information to save to a database with the user_id. But there is a page refresh in between. So my question is how to pass it through this chain. I thought about the redirect url as a query param, and that works with the
    Site URL
    but I can't work out how to use it with the
    Additional Redirect URLs
    in the auth settings
  • h

    hotbelgo

    03/06/2022, 7:05 AM
    in other words, a redirect to
    https://abc.netlify.app/?x=y
    works, but https://localhost:3000/?x=y does not
  • h

    hotbelgo

    03/06/2022, 7:06 AM
    with signUpByEmail the SDK provides ways of doing this for you, but signUp does not exist, as such, got oauth methods
  • u

    *✿❀♡cynthii♡❀✿*

    03/07/2022, 4:48 AM
    How do I implement "Remember Me" functionality? My thought was to use sessionStorage instead of localStorage but how do I point supabase there? (Using nextjs/react if that matters)
    c
    • 2
    • 5
  • c

    chipilov

    03/07/2022, 7:34 AM
    Implementing Remember Me
  • v

    v.naeimabadi

    03/07/2022, 10:58 AM
    i am getting error for subscribing for android 10 in react-native any idea .subscribe((status, e) => console.log(status, e)) i got: status= RETRYING_AFTER_TIMEOUT ,error= undefined and then status= SUBSCRIPTION_ERROR ,error= undefined
    g
    • 2
    • 1
  • g

    garyaustin

    03/07/2022, 2:02 PM
    Subscription error
  • m

    Martin INDIE MAKERS

    03/08/2022, 3:48 PM
    hey since 2 days my upload function doesn't work anymore. i can upload but the data is broken. I didn't change my code just did minor supabase upgrade. I use blob format to upload do you have same issue ? if i save the blob in my computer just before send the format is correct.
  • m

    Martin INDIE MAKERS

    03/08/2022, 3:48 PM
    the weird part is there on supabase admin
    image/png - 2 bytes
  • m

    Martin INDIE MAKERS

    03/08/2022, 3:49 PM
    when i check before send i have
    image/png
  • m

    Martin INDIE MAKERS

    03/08/2022, 3:50 PM
    my upload is pretty simple
    Copy code
    await supabase
          .storage
          .from('images')
          .upload(`${userId.value}/${file.name}`, blob, {
            contentType: file.mimeType,
          })
  • m

    Martin INDIE MAKERS

    03/08/2022, 4:06 PM
    it's seems if i remove custom fetch it fix the issue. maybe relate to the last change in supabase storage
    g
    • 2
    • 5
1...505152...81Latest