GithubHelp home page GithubHelp logo

hmmhmmhm / rls-ts Goto Github PK

View Code? Open in Web Editor NEW
54.0 1.0 1.0 11 KB

Helps you write Supabase Row Level Security (RLS) in Typescript.

Home Page: https://supabase-rls.up.railway.app

License: MIT License

TypeScript 100.00%
supabase rls row-level-security rbac role-based-access-control typescript

rls-ts's Introduction

๐Ÿงถ Supabase RLS in Typescript

Watch the video Actual Image

๐Ÿ“œ Helps you write Supabase Row Level Security (RLS) in Typescript. (* plv8)


๐Ÿš€ Usage

New website opned!!: https://supabase-rls.up.railway.app (Web Source)

1. Clone And Install

git clone https://github.com/hmmhmmhm/rls-ts.git
cd ./rls-ts
npm install

2. Update Project Types

Please read the guide and follow it to read the type of Supabase project. Generating Supabase Types

3. Create or Modify File

Create or modify the example.ts file in the ./src directory.

export default createPolicy<TABLE_NAME>((context) => {
  // TODO: Your policy logic
  return true;
});

Below is an example of use.

export default createPolicy<"channels">((context) => {
  // * Allow only creators to update their own channels
  return context.row.created_by === context.auth.uid();
});

4. Build

After entering the command below, a file is created, such as build/example.plv8.sql.

npm run build

Copying the translated script and pasting it into the desired policy within Supabase takes effect. (Below is an example of sql file.)

-- example.ts.plv8.sql
boolean as $$
function createPolicy(cb) {
    cb({
        row: globalThis,
        function: globalThis,
        auth: globalThis.auth,
        plv8: globalThis.plv8
    });
}
return createPolicy(function(context) {
    // Allow only creators to update their own channels
    if (context.row.created_by === context.auth.uid()) return true;
});
$$ language plv8;

โœ… License

MIT Licensed.

rls-ts's People

Contributors

hmmhmmhm avatar nopenguinsintheartic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

tribe-health

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.