https://supabase.com/ logo
Join Discord
Powered by
# help
  • o

    oliviercp

    12/27/2021, 9:29 PM
    Hey! I’m running supabase db reset using the cli with no migration and when i try to signup a user after i get “Database error finding user”
  • o

    oliviercp

    12/27/2021, 9:30 PM
    Anyone have an idea on whats the problem?
  • d

    dhruv_casa

    12/27/2021, 10:10 PM
    How do I fetch the user for NextJS SSR? There's no auth api that's working. I've tried: 1. context.req.cookies['sb:token'] -> It doesn't persist and goes away very quickly 2. supabase.auth.api.getUserByCookie(context.req) -> doesn't work 3. supabase.auth.api.getUser(access_token) -> works, but you need access token I can see that the user is logged in with supabase.auth.token stored in localStorage, but how do I fetch that server side in nextjs?
  • b

    binajmen

    12/27/2021, 10:24 PM
    Copy code
    ts
    export const getServerSideProps: GetServerSideProps = async ({ req }) => {
      const { user } = await supabase.auth.api.getUserByCookie(req);
    
      if (!user) {
        return { props: {}, redirect: { destination: '/signin', permanent: false } };
      }
    
      return {
        props: {
          user,
        }
      };
    }
    I have the following that works
  • b

    binajmen

    12/27/2021, 10:25 PM
    You must have something similar to `/pages/api/auth.ts`:
    Copy code
    ts
    import { supabase } from '../../utils/supabase';
    
    import type { NextApiRequest, NextApiResponse } from 'next'
    
    type Data = {
      name: string
    }
    
    export default function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
      supabase.auth.api.setAuthCookie(req, res);
    }
  • b

    binajmen

    12/27/2021, 10:25 PM
    and call the api `onAuthStateChange`:
    Copy code
    ts
        const { data: authListener } = supabaseClient.auth.onAuthStateChange(
          // async (event, session) => {
          (event, session) => {
            setSession(session);
            setUser(session?.user ?? null);
    
            // Send session to /api/auth route to set the auth cookie
            fetch('/api/auth', {
              method: 'POST',
              headers: new Headers({ 'Content-type': 'application/json' }),
              credentials: 'same-origin',
              body: JSON.stringify({ event, session }),
            }).then(res => res.json());
          }
        );
  • d

    dhruv_casa

    12/27/2021, 10:31 PM
    I'm doing exactly this. Have you tried it over hours / days? For some reason the getUserByCookie returns null after some time and you have to login again, basically the auth doesn't persist
  • d

    dhruv_casa

    12/27/2021, 10:31 PM
    Even though localStorage has the supabase token
  • l

    lorencerri

    12/28/2021, 6:17 AM
    Is it possible to restrict which columns users can modify? I can't seem to find any examples of this (e.g. allowing a user to change the content column in a posts table but not the post timestamp)
  • b

    binajmen

    12/28/2021, 6:42 AM
    it expires at some point
  • b

    binajmen

    12/28/2021, 6:54 AM
    Good catch! You might consider create an issue so they can fix the doc 😉
  • s

    skyscanner

    12/28/2021, 7:38 AM
    Hi Guys, hope you are well. I am trying to perform a userlogin through the auth.setAuth(token), I have minted the token myself using the supabase secret but the session info always returns user = null and any db calls donot pass through the RLS?
  • s

    skyscanner

    12/28/2021, 7:44 AM
    Any ideas how I can overcome this ? Is anyone using the setAuth method successfully with a custom minted token?
  • k

    ktosiek

    12/28/2021, 8:07 AM
    have you checked the return value from
    .setAuth
    ?
  • s

    skyscanner

    12/28/2021, 8:50 AM
    Hi @User , I always get user = null
  • s

    skyscanner

    12/28/2021, 8:51 AM
    Perhaps I am minting the token incorrectly, have a look at this:
  • s

    skyscanner

    12/28/2021, 8:52 AM
    here is an example of the decoded payload : { "aud": "authenticated", "exp": 1640508097, "sub": "7d5ba40f-ba32-42b4-b8d6-819da7a25640", "email": "sky@skycanner.com", "phone": "", "app_metadata": { "provider": "email", "providers": [ "email" ] }, "user_metadata": {}, "role": "authenticated" }
  • k

    ktosiek

    12/28/2021, 9:08 AM
    Ohh, I see
  • k

    ktosiek

    12/28/2021, 9:14 AM
    @User setAuth doesn't set the user, just the access token. You can get the current user with `.auth.api.getUser(access_token)`: https://supabase.com/docs/reference/javascript/auth-api-getuser
  • k

    ktosiek

    12/28/2021, 9:15 AM
    I have no idea how to get a "logged in client", with working session and user, just from the JWT - but if you could get a refresh_token, then you can
    .signIn({refresh_token: ...})
    .
  • b

    bh

    12/28/2021, 10:15 AM
    Is there a way to pause an instance. I migrated to a new instance but want to test it before deleting the old one. I need to pause the old instance so that I can catch any clients that are still depending on it
  • s

    skyscanner

    12/28/2021, 10:29 AM
    Thanks @User I succeeded with that method
  • k

    ktosiek

    12/28/2021, 10:54 AM
    No idea if you can pause an instance, but you can check the logs in your project's Settings
  • k

    ktosiek

    12/28/2021, 10:54 AM
    that will tell you if anyone still uses it
  • v

    vabatta

    12/28/2021, 4:05 PM
    I'm trying to make a fuzzy search with the following code on a table
    products
    that has a
    many-to-many
    relationship to
    categories
    so that
    searchQuery
    can be either an
    ilike of product.name OR ilike of category.name
    but I cannot figure out why it doesn't work
    Copy code
    ts
    supabase()
      .from<ProductWithIngredients>('products')
      .select('*, ingredients(*), products_ingredients(*), categories(*)')
      .or(`name.ilike.%${searchQuery}%`)
      .or(`name.ilike.%${searchQuery}%`, { foreignTable: 'categories' })
      .throwOnError()
      .then((response) => (isNull(response.data) ? [] : response.data));
    Any idea?
    s
    • 2
    • 4
  • v

    vabatta

    12/28/2021, 4:25 PM
    The query that I'm trying to achieve looks like this
    Copy code
    sql
    select * from products 
    inner join products_categories on products.id = products_categories.product_id 
    inner join categories on categories.id = products_categories.category_id
    where categories.name ilike '%mari%' -- this filters on the category name
    or products.name ilike '%mari%' -- this filters on the product name
  • w

    Walt

    12/28/2021, 8:04 PM
    Hello! We've deployed an app on Supabase and it's running, people are signing up, uploading images. It's groovy. We're trying to figure out something we should have done before launching it.. We want to copy our production data. Using the basic instructions on https://supabase.com/docs/guides/database#migrating-between-projects we've cloned the database, + storage metadata, but the database cannot be used because it throws authentication errors accessing the data. Supabase support says these aren't really authentication errors, something in the stack must be misreporting that, apparently its because the storage objects aren't migrated. Our efforts to migrate the storage objects manually are not working (like, how would you even do that?) - I believe these things are hosted on AWS so if we simply had the keys to our bucket it would be fairly trivial to copy the data. Does anyone have any ideas how to achieve this?
  • u

    user

    12/29/2021, 9:16 AM
    Hi. I'm trying to contact support via the contact form and it is telling me there is a 500 error.
  • c

    chipilov

    12/29/2021, 9:18 AM
    It's a known issue currently being investigated: https://github.com/supabase/supabase/issues/4709. In the meantime, you can probably send an email to support@supabase.io
  • u

    user

    12/29/2021, 9:24 AM
    @User - Thanks. Willdo.
1...175176177...316Latest