Skip to content

Instantly share code, notes, and snippets.

View mxmzb's full-sized avatar
🍜
Probably eating

Maxim mxmzb

🍜
Probably eating
View GitHub Profile

Implement user API keys with Supabase

Rationale

JWTs are at the heart of Supabase authorization, but sometimes we wanna build an app that also gives users access via API keys; or perhaps only exclusively via API keys. As you may know, using JWTs as API keys makes them difficult to revoke and therefore a security issue.

We also want to ensure this doesn't significantly add to RLS polices, if at all.

Finally, we'd love to have this handled by Supabase and do as little as possible in our framework. This simplifies our code and reduces third-party libraries.

Solution

const findSumInArray = (arr, sum) => {
let needle = [];
let tmpSum = 0;
for(let i = 0; i < arr.length; i++) {
tmpSum = tmpSum + arr[i];
needle.push(arr[i]);
if(sum === tmpSum) {
return needle;
@mxmzb
mxmzb / apolloClient.js
Last active September 25, 2019 11:24
Apollo link
import { ApolloClient } from "apollo-client";
import link from "./apolloLink";
const client = new ApolloClient({
link,
});
export default client;
@mxmzb
mxmzb / Separator.js
Created October 7, 2018 15:02
A RN module
import React from "react";
import styled, { ThemeProvider } from "styled-components";
import config from "../../config";
const Background = styled.View`
width: ${props => props.width}px;
height: ${props => props.height}px;
background-color: ${props => props.background};
justify-content: flex-end;
`;
@mxmzb
mxmzb / Installer Log 09-27-18.txt
Created September 27, 2018 08:21
OSX Mojave Installer Log
Sep 27 07:55:20 localhost powerd[173]: powerd process is started
Sep 27 07:55:23 localhost Unknown[522]: kern.boottime: { sec = 1538034904, usec = 0 } Thu Sep 27 07:55:04 2018
Sep 27 07:55:23 localhost Installer Progress[181]: Progress UI App Starting
Sep 27 07:55:28 localhost Unknown[535]: Launching the Language Chooser for an OS Install
Sep 27 07:55:28 localhost bspowerassertiontool[530]: Tool exited successfully (0).
Sep 27 07:55:28 localhost launchprogresswindow[533]: ISAP: Show progress UI called
Sep 27 07:55:52 MacBook-Pro Installer Progress[181]: IASGetCurrentInstallPhaseList: phases = (
{
ConclusionDelay = 0;
InstallPhase = "Boot 1";
@mxmzb
mxmzb / screen.js
Last active August 27, 2018 13:22
rn screen file
import React, { Fragment } from "react";
import { SafeAreaView } from "react-native";
import { Query } from "react-apollo";
import { scheduleQuery } from "src/modules/Schedule/graphql/queries";
import { Header, HeaderConfig } from "src/modules/shared/components";
import { ScheduleFull } from "src/modules/Schedule/components";
export default class ScheduleScreen extends React.PureComponent {
static navigationOptions = ({ navigation }) => {
@mxmzb
mxmzb / .babelrc
Created July 11, 2018 16:29
babel-jest in a monorepo
// .babelrc in packages/foodloc-models/.babelrc
{
"presets": ["env", "react"],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-transform-modules-commonjs",
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-export-default-from"
]
@mxmzb
mxmzb / index.js
Created June 29, 2018 10:47
Exercise Meta
class ExerciseMeta {
constructor(metaArr) {
// ... noise
}
format(type, value) {
// ... noise
return ["somevalue"]
}
@mxmzb
mxmzb / mutation.js
Created May 21, 2018 20:45
graphql nested objects
// this is client side
import gql from "graphql-tag";
export const createStoreMutation = gql`
mutation(
$name: String!
$brand: ID!
$country: String!
$region: String!
@mxmzb
mxmzb / Auth.js
Created October 5, 2017 12:35
Auth0.com authentication
import Auth0Lock from 'auth0-lock';
// import auth0 from 'auth0-js';
import decode from 'jwt-decode';
// import { browserHistory } from 'react-router';
import history from './history';
export default class Auth {
lock = new Auth0Lock('GNx0zoCnEmuSz5T3JylON5hxEhMSe9Ki', 'artmarqet.auth0.com', {