The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: add refine user management example
necatiozmen8b97431fb134
diff --git a/examples/user-management/refine-user-management/.eslintrc.cjs b/examples/user-management/refine-user-management/.eslintrc.cjsnew file mode 100644index 00000000000..595490efccc--- /dev/null+++ b/examples/user-management/refine-user-management/.eslintrc.cjs@@ -0,0 +1,16 @@+/* eslint-env node */++module.exports = {+ env: { browser: true, es2020: true },+ extends: [+ "eslint:recommended",+ "plugin:@typescript-eslint/recommended",+ "plugin:react-hooks/recommended",+ ],+ parser: "@typescript-eslint/parser",+ parserOptions: { ecmaVersion: "latest", sourceType: "module" },+ plugins: ["react-refresh"],+ rules: {+ "react-refresh/only-export-components": "warn",+ },+};diff --git a/examples/user-management/refine-user-management/.gitignore b/examples/user-management/refine-user-management/.gitignorenew file mode 100644index 00000000000..24cdedf82f1--- /dev/null+++ b/examples/user-management/refine-user-management/.gitignore@@ -0,0 +1,23 @@+# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.++# dependencies+/node_modules+/.pnp+.pnp.js++# testing+/coverage++# production+/build++# misc+.DS_Store+.env.local+.env.development.local+.env.test.local+.env.production.local++npm-debug.log*+yarn-debug.log*+yarn-error.log*\ No newline at end of filediff --git a/examples/user-management/refine-user-management/.npmrc b/examples/user-management/refine-user-management/.npmrcnew file mode 100644index 00000000000..acb88cc765e--- /dev/null+++ b/examples/user-management/refine-user-management/.npmrc@@ -0,0 +1,2 @@+legacy-peer-deps=true+strict-peer-dependencies=false\ No newline at end of filediff --git a/examples/user-management/refine-user-management/README.MD b/examples/user-management/refine-user-management/README.MDnew file mode 100644index 00000000000..fe6e8da2b15--- /dev/null+++ b/examples/user-management/refine-user-management/README.MD@@ -0,0 +1,121 @@+# Supabase refine User Management++This repo is a quick sample of how you can get started building apps using [refine](https://github.com/refinedev/refine) and Supabase: users can sign up with a magic link and then update their account with public profile information, including a profile image.++++## About refine++[refine](https://github.com/refinedev/refine) is a React-based framework for building data-intensive applications in no time ✨++refine offers lots of out-of-the box functionality for rapid development, without compromising extreme customizability. Use-cases include, but are not limited to admin panels, B2B applications and dashboards.+++- To learn more about **refine**, please check out the [Documentation](https://refine.dev/docs)+- [Step up to refine tutorials.](https://refine.dev/docs/tutorial/introduction/index/)++## Available Scripts+### Running the development server.++```bash+npm run dev+```++### Building for production.++```bash+npm run build+```+++## Build from scratch++### 1. Create new project++Sign up to Supabase - [https://app.supabase.com](https://app.supabase.com) and create a new project. Wait for your database to start.++### 2. Run "User Management" Quickstart++Once your database has started, head over to your project's `SQL Editor` and run the "User Management Starter" quickstart. On the `SQL editor` page, scroll down until you see `User Management Starter: Sets up a public Profiles table which you can access with your API`. Click that, then click `RUN` to execute that query and create a new `profiles` table. When that's finished, head over to the `Table Editor` and see your new `profiles` table.++### 3. Get the URL and Key++Go to the Project Settings (the cog icon), open the API tab, and find your API URL and `anon` key, you'll need these in the next step.++The `anon` key is your client-side API key. It allows "anonymous access" to your database, until the user has logged in. Once they have logged in, the keys will switch to the user's own login token. This enables row level security for your data. Read more about this [below](#postgres-row-level-security).++++**_NOTE_**: The `service_role` key has full access to your data, bypassing any security policies. These keys have to be kept secret and are meant to be used in server environments and never on a client or browser.++### 4. Env vars++Create a file in this folder `.env.local`++```+VITE_SUPABASE_URL=YOUR_SUPABASE_URL+VITE_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY+```++Populate this file with your URL and Key.++### 5. Run the application++Run the application: `npm run dev`. Open your browser to `https://localhost:5173/` and you are ready to go 🚀.++## Supabase details++### Postgres Row level security++This project uses very high-level Authorization using Postgres' Role Level Security.+When you start a Postgres database on Supabase, we populate it with an `auth` schema, and some helper functions.+When a user logs in, they are issued a JWT with the role `authenticated` and their UUID.+We can use these details to provide fine-grained control over what each user can and cannot do.++This is a trimmed-down schema, with the policies:++```sql+-- Create a table for Public Profiles+create table profiles (+ id uuid references auth.users not null,+ updated_at timestamp with time zone,+ username text unique,+ avatar_url text,+ website text,+ primary key (id),+ unique(username),+ constraint username_length check (char_length(username) >= 3)+);+alter table profiles enable row level security;+create policy "Public profiles are viewable by everyone."+ on profiles for select+ using ( true );+create policy "Users can insert their own profile."+ on profiles for insert+ with check ( auth.uid() = id );+create policy "Users can update own profile."+ on profiles for update+ using ( auth.uid() = id );+-- Set up Realtime!+begin;+ drop publication if exists supabase_realtime;+ create publication supabase_realtime;+commit;+alter publication supabase_realtime add table profiles;+-- Set up Storage!+insert into storage.buckets (id, name)+values ('avatars', 'avatars');+create policy "Avatar images are publicly accessible."+ on storage.objects for select+ using ( bucket_id = 'avatars' );+create policy "Anyone can upload an avatar."+ on storage.objects for insert+ with check ( bucket_id = 'avatars' );+```++++## License++MIT+diff --git a/examples/user-management/refine-user-management/index.html b/examples/user-management/refine-user-management/index.htmlnew file mode 100644index 00000000000..17e72529889--- /dev/null+++ b/examples/user-management/refine-user-management/index.html@@ -0,0 +1,41 @@+<!DOCTYPE html>+<html lang="en">+ <head>+ <meta charset="utf-8" />+ <link rel="icon" href="/favicon.ico" />+ <meta name="viewport" content="width=device-width, initial-scale=1" />+ <meta name="theme-color" content="#000000" />+ <meta+ name="description"+ content="refine | Build your React-based CRUD applications, without constraints."+ />+ <meta+ data-rh="true"+ property="og:image"+ content="https://refine.dev/img/refine_social_new.png"+ />+ <meta+ data-rh="true"+ name="twitter:image"+ content="https://refine.dev/img/refine_social_new.png"+ />+ <title>+ refine - Build your React-based CRUD applications, without constraints.+ </title>+ </head>+ <body>+ <noscript>You need to enable JavaScript to run this app.</noscript>+ <div id="root"></div>+ <script type="module" src="/src/index.tsx"></script>+ <!--+ This HTML file is a template.+ If you open it directly in the browser, you will see an empty page.++ You can add webfonts, meta tags, or analytics to this file.+ The build step will place the bundled scripts into the <body> tag.++ To begin the development, run `npm dev` or `yarn start`.+ To create a production bundle, use `npm run build` or `yarn build`.+ -->+ </body>+</html>diff --git a/examples/user-management/refine-user-management/package.json b/examples/user-management/refine-user-management/package.jsonnew file mode 100644index 00000000000..f91969089ae--- /dev/null+++ b/examples/user-management/refine-user-management/package.json@@ -0,0 +1,50 @@+{+ "name": "refine-user-management",+ "version": "0.1.0",+ "private": true,+ "type": "module",+ "dependencies": {+ "@refinedev/cli": "^2.5.1",+ "@refinedev/core": "^4.5.8",+ "@refinedev/inferencer": "^3.1.4",+ "@refinedev/kbar": "^1.1.0",+ "@refinedev/react-hook-form": "^4.4.0",+ "@refinedev/react-router-v6": "^4.1.0",+ "@refinedev/supabase": "^5.0.0",+ "react": "^18.0.0",+ "react-dom": "^18.0.0",+ "react-hook-form": "^7.45.0",+ "react-router-dom": "^6.8.1"+ },+ "devDependencies": {+ "@types/node": "^18.16.2",+ "@types/react": "^18.0.0",+ "@types/react-dom": "^18.0.0",+ "@typescript-eslint/eslint-plugin": "^5.57.1",+ "@typescript-eslint/parser": "^5.57.1",+ "@vitejs/plugin-react": "^4.0.0",+ "eslint": "^8.38.0",+ "eslint-plugin-react-hooks": "^4.6.0",+ "eslint-plugin-react-refresh": "^0.3.4",+ "typescript": "^4.7.4",+ "vite": "^4.3.1"+ },+ "scripts": {+ "dev": "refine dev",+ "build": "tsc && refine build",+ "preview": "refine start",+ "refine": "refine"+ },+ "browserslist": {+ "production": [+ ">0.2%",+ "not dead",+ "not op_mini all"+ ],+ "development": [+ "last 1 chrome version",+ "last 1 firefox version",+ "last 1 safari version"+ ]+ }+}diff --git a/examples/user-management/refine-user-management/public/favicon.ico b/examples/user-management/refine-user-management/public/favicon.iconew file mode 100644index 00000000000..2f05c5f484fBinary files /dev/null and b/examples/user-management/refine-user-management/public/favicon.ico differdiff --git a/examples/user-management/refine-user-management/src/App.css b/examples/user-management/refine-user-management/src/App.cssnew file mode 100644index 00000000000..c8af4ebcc94--- /dev/null+++ b/examples/user-management/refine-user-management/src/App.css@@ -0,0 +1,382 @@+html,+body {+ --custom-font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu,+ Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;+ --custom-bg-color: #101010;+ --custom-panel-color: #222;+ --custom-box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.8);+ --custom-color: #fff;+ --custom-color-brand: #24b47e;+ --custom-color-secondary: #666;+ --custom-border: 1px solid #333;+ --custom-border-radius: 5px;+ --custom-spacing: 5px;++ padding: 0;+ margin: 0;+ font-family: var(--custom-font-family);+ background-color: var(--custom-bg-color);+}++* {+ color: var(--custom-color);+ font-family: var(--custom-font-family);+ box-sizing: border-box;+}++html,+body,+#__next {+ height: 100vh;+ width: 100vw;+ overflow-x: hidden;+}++/* Grid */++.container {+ width: 90%;+ margin-left: auto;+ margin-right: auto;+}+.row {+ position: relative;+ width: 100%;+}+.row [class^='col'] {+ float: left;+ margin: 0.5rem 2%;+ min-height: 0.125rem;+}+.col-1,+.col-2,+.col-3,+.col-4,+.col-5,+.col-6,+.col-7,+.col-8,+.col-9,+.col-10,+.col-11,+.col-12 {+ width: 96%;+}+.col-1-sm {+ width: 4.33%;+}+.col-2-sm {+ width: 12.66%;+}+.col-3-sm {+ width: 21%;+}+.col-4-sm {+ width: 29.33%;+}+.col-5-sm {+ width: 37.66%;+}+.col-6-sm {+ width: 46%;+}+.col-7-sm {+ width: 54.33%;+}+.col-8-sm {+ width: 62.66%;+}+.col-9-sm {+ width: 71%;+}+.col-10-sm {+ width: 79.33%;+}+.col-11-sm {+ width: 87.66%;+}+.col-12-sm {+ width: 96%;+}+.row::after {+ content: '';+ display: table;+ clear: both;+}+.hidden-sm {+ display: none;+}++@media only screen and (min-width: 33.75em) {+ /* 540px */+ .container {+ width: 80%;+ }+}++@media only screen and (min-width: 45em) {+ /* 720px */+ .col-1 {+ width: 4.33%;+ }+ .col-2 {+ width: 12.66%;+ }+ .col-3 {+ width: 21%;+ }+ .col-4 {+ width: 29.33%;+ }+ .col-5 {+ width: 37.66%;+ }+ .col-6 {+ width: 46%;+ }+ .col-7 {+ width: 54.33%;+ }+ .col-8 {+ width: 62.66%;+ }+ .col-9 {+ width: 71%;+ }+ .col-10 {+ width: 79.33%;+ }+ .col-11 {+ width: 87.66%;+ }+ .col-12 {+ width: 96%;+ }+ .hidden-sm {+ display: block;+ }+}++@media only screen and (min-width: 60em) {+ /* 960px */+ .container {+ width: 75%;+ max-width: 60rem;+ }+}++/* Forms */++label {+ display: block;+ margin: 5px 0;+ color: var(--custom-color-secondary);+ font-size: 0.8rem;+ text-transform: uppercase;+}++input {+ width: 100%;+ border-radius: 5px;+ border: var(--custom-border);+ padding: 8px;+ font-size: 0.9rem;+ background-color: var(--custom-bg-color);+ color: var(--custom-color);+}++input[disabled] {+ color: var(--custom-color-secondary);+}++/* Utils */++.block {+ display: block;+ width: 100%;+}+.inline-block {+ display: inline-block;+ width: 100%;+}+.flex {+ display: flex;+}+.flex.column {+ flex-direction: column;+}+.flex.row {+ flex-direction: row;+}+.flex.flex-1 {+ flex: 1 1 0;+}+.flex-end {+ justify-content: flex-end;+}+.flex-center {+ justify-content: center;+}+.items-center {+ align-items: center;+}+.text-sm {+ font-size: 0.8rem;+ font-weight: 300;+}+.text-right {+ text-align: right;+}+.font-light {+ font-weight: 300;+}+.opacity-half {+ opacity: 50%;+}++/* Button */++button,+.button {+ color: var(--custom-color);+ border: var(--custom-border);+ background-color: var(--custom-bg-color);+ display: inline-block;+ text-align: center;+ border-radius: var(--custom-border-radius);+ padding: 0.5rem 1rem;+ cursor: pointer;+ text-align: center;+ font-size: 0.9rem;+ text-transform: uppercase;+}++button.primary,+.button.primary {+ background-color: var(--custom-color-brand);+ border: 1px solid var(--custom-color-brand);+}++/* Widgets */++.card {+ width: 100%;+ display: block;+ border: var(--custom-border);+ border-radius: var(--custom-border-radius);+ padding: var(--custom-spacing);+}++.avatar {+ border-radius: var(--custom-border-radius);+ overflow: hidden;+ max-width: 100%;+}+.avatar.image {+ object-fit: cover;+}+.avatar.no-image {+ background-color: #333;+ border: 1px solid rgb(200, 200, 200);+ border-radius: 5px;+}++.footer {+ position: absolute;+ max-width: 100%;+ bottom: 0;+ left: 0;+ right: 0;+ display: flex;+ flex-flow: row;+ border-top: var(--custom-border);+ background-color: var(--custom-bg-color);+}+.footer div {+ padding: var(--custom-spacing);+ display: flex;+ align-items: center;+ width: 100%;+}+.footer div > img {+ height: 20px;+ margin-left: 10px;+}+.footer > div:first-child {+ display: none;+}+.footer > div:nth-child(2) {+ justify-content: left;+}++@media only screen and (min-width: 60em) {+ /* 960px */+ .footer > div:first-child {+ display: flex;+ }+ .footer > div:nth-child(2) {+ justify-content: center;+ }+}++@keyframes spin {+ from {+ transform: rotate(0deg);+ }+ to {+ transform: rotate(360deg);+ }+}++.mainHeader {+ width: 100%;+ font-size: 1.3rem;+ margin-bottom: 20px;+}++.avatarPlaceholder {+ border: var(--custom-border);+ border-radius: var(--custom-border-radius);+ width: 35px;+ height: 35px;+ background-color: rgba(255, 255, 255, 0.2);+ display: flex;+ align-items: center;+ justify-content: center;+}++.form-widget {+ display: flex;+ flex-direction: column;+ gap: 20px;+}++.form-widget > .button {+ display: flex;+ align-items: center;+ justify-content: center;+ border: none;+ background-color: #444444;+ text-transform: none !important;+ transition: all 0.2s ease;+}++.form-widget .button:hover {+ background-color: #2a2a2a;+}++.form-widget .button > .loader {+ width: 17px;+ animation: spin 1s linear infinite;+ filter: invert(1);+}++.visually-hidden:not(:focus):not(:active) {+ clip: rect(0 0 0 0);+ clip-path: inset(50%);+ height: 1px;+ overflow: hidden;+ position: absolute;+ white-space: nowrap;+ width: 1px;+}diff --git a/examples/user-management/refine-user-management/src/App.tsx b/examples/user-management/refine-user-management/src/App.tsxnew file mode 100644index 00000000000..98e42e2e346--- /dev/null+++ b/examples/user-management/refine-user-management/src/App.tsx@@ -0,0 +1,58 @@+import { Authenticated, Refine } from '@refinedev/core';+import { RefineKbar, RefineKbarProvider } from '@refinedev/kbar';++import routerBindings, {+ CatchAllNavigate,+ DocumentTitleHandler,+ UnsavedChangesNotifier,+} from '@refinedev/react-router-v6';+import { dataProvider, liveProvider } from '@refinedev/supabase';+import { BrowserRouter, Outlet, Route, Routes } from 'react-router-dom';+import './App.css';+import authProvider from './authProvider';+import { supabaseClient } from './utility';+import Account from './components/account';+import Auth from './components/auth';++function App() {+ return (+ <BrowserRouter>+ <RefineKbarProvider>+ <Refine+ dataProvider={dataProvider(supabaseClient)}+ liveProvider={liveProvider(supabaseClient)}+ authProvider={authProvider}+ routerProvider={routerBindings}+ options={{+ syncWithLocation: true,+ warnWhenUnsavedChanges: true,+ }}+ >+ <Routes>+ <Route+ element={+ <Authenticated+ fallback={<CatchAllNavigate to="/login" />}+ >+ <Outlet />+ </Authenticated>+ }+ >+ <Route index element={<Account />} />+ </Route>+ <Route+ element={<Authenticated fallback={<Outlet />} />}+ >+ <Route path="/login" element={<Auth />} />+ </Route>+ </Routes>+ <RefineKbar />+ <UnsavedChangesNotifier />+ <DocumentTitleHandler />+ </Refine>+ </RefineKbarProvider>+ </BrowserRouter>+ );+}++export default App;diff --git a/examples/user-management/refine-user-management/src/authProvider.ts b/examples/user-management/refine-user-management/src/authProvider.tsnew file mode 100644index 00000000000..d24fb768fc1--- /dev/null+++ b/examples/user-management/refine-user-management/src/authProvider.ts@@ -0,0 +1,91 @@+import { AuthBindings } from "@refinedev/core";++import { supabaseClient } from "./utility";++const authProvider: AuthBindings = {+ login: async ({ email }) => {+ try {+ const { error } = await supabaseClient.auth.signInWithOtp({ email });++ if (!error) {+ alert("Check your email for the login link!");+ return {+ success: true,+ };+ };++ throw error;+ } catch (e: any) {+ alert(e.message);+ return {+ success: false,+ e,+ };+ }+ },+ logout: async () => {+ const { error } = await supabaseClient.auth.signOut();++ if (error) {+ return {+ success: false,+ error,+ };+ }++ return {+ success: true,+ redirectTo: "/",+ };+ },+ onError: async (error) => {+ console.error(error);+ return { error };+ },+ check: async () => {+ try {+ const { data } = await supabaseClient.auth.getSession();+ const { session } = data;++ if (!session) {+ return {+ authenticated: false,+ error: {+ message: "Check failed",+ name: "Session not found",+ },+ logout: true,+ redirectTo: "/login",+ };+ }+ } catch (error: any) {+ return {+ authenticated: false,+ error: error || {+ message: "Check failed",+ name: "Not authenticated",+ },+ logout: true,+ redirectTo: "/login",+ };+ }++ return {+ authenticated: true,+ };+ },+ getIdentity: async () => {+ const { data } = await supabaseClient.auth.getUser();++ if (data?.user) {+ return {+ ...data.user,+ name: data.user.email,+ };+ }++ return null;+ },+};++export default authProvider;diff --git a/examples/user-management/refine-user-management/src/components/account.tsx b/examples/user-management/refine-user-management/src/components/account.tsxnew file mode 100644index 00000000000..08292fa4714--- /dev/null+++ b/examples/user-management/refine-user-management/src/components/account.tsx@@ -0,0 +1,107 @@+import { BaseKey, useGetIdentity, useLogout } from "@refinedev/core";+import { useForm } from "@refinedev/react-hook-form";+import { Controller } from "react-hook-form";+import Avatar from "./avatar";++interface IUserIdentity {+ id?: BaseKey;+ username: string;+ name: string;+};++export interface IProfile {+ id?: string;+ username?: string;+ website?: string;+ avatar_url?: string;+};++export default function Account() {+ const { data: userIdentity } = useGetIdentity<IUserIdentity>();++ const { mutate: logOut } = useLogout();++ const {+ refineCore: { formLoading, queryResult, onFinish },+ register,+ control,+ handleSubmit,+ } = useForm<IProfile>({+ refineCoreProps: {+ resource: "profiles",+ action: "edit",+ id: userIdentity?.id,+ redirect: false,+ onMutationError: (data) => alert(data?.message),+ },+ });++ return (+ <div className="container" style={{ padding: "50px 0 100px 0" }}>+ <form onSubmit={handleSubmit(onFinish)} className="form-widget">+ <Controller+ control={control}+ name="avatar_url"+ render={({ field }) => {+ return (+ <Avatar+ url={field.value}+ size={150}+ onUpload={(filePath) => {+ onFinish({+ ...queryResult?.data?.data,+ avatar_url: filePath,+ onMutationError: (data: { message: string; }) => alert(data?.message),+ });+ field.onChange({+ target: {+ value: filePath,+ },+ });+ }}+ />+ );+ }}+ />+ <div>+ <label htmlFor="email">Email</label>+ <input+ id="email"+ name="email"+ type="text"+ value={userIdentity?.name}+ disabled+ />+ </div>+ <div>+ <label htmlFor="username">Name</label>+ <input id="username" type="text" {...register("username")} />+ </div>+ <div>+ <label htmlFor="website">Website</label>+ <input id="website" type="url" {...register("website")} />+ </div>++ <div>+ <button+ className="button block primary"+ type="submit"+ disabled={formLoading}+ >+ {formLoading ? "Loading ..." : "Update"}+ </button>+ </div>++ <div>+ <button+ className="button block"+ type="button"+ onClick={() => logOut()}+ >+ Sign Out+ </button>+ </div>+ </form>+ </div>+ );+};diff --git a/examples/user-management/refine-user-management/src/components/auth.tsx b/examples/user-management/refine-user-management/src/components/auth.tsxnew file mode 100644index 00000000000..1c043ffcb31--- /dev/null+++ b/examples/user-management/refine-user-management/src/components/auth.tsx@@ -0,0 +1,38 @@+import { useState } from "react";+import { useLogin } from "@refinedev/core";++export default function Auth() {+ const [email, setEmail] = useState("");+ const { isLoading, mutate: login } = useLogin();++ const handleLogin = async (event: { preventDefault: () => void }) => {+ event.preventDefault();+ login({ email });+ };++ return (+ <div className="row flex flex-center container">+ <div className="col-6 form-widget">+ <h1 className="header">Supabase + refine</h1>+ <p className="description">Sign in via magic link with your email below</p>+ <form className="form-widget" onSubmit={handleLogin}>+ <div>+ <input+ className="inputField"+ type="email"+ placeholder="Your email"+ value={email}+ required={true}+ onChange={(e) => setEmail(e.target.value)}+ />+ </div>+ <div>+ <button className={"button block"} disabled={isLoading}>+ {isLoading ? <span>Loading</span> : <span>Send magic link</span>}+ </button>+ </div>+ </form>+ </div>+ </div>+ );+};diff --git a/examples/user-management/refine-user-management/src/components/avatar.tsx b/examples/user-management/refine-user-management/src/components/avatar.tsxnew file mode 100644index 00000000000..0feb85b2982--- /dev/null+++ b/examples/user-management/refine-user-management/src/components/avatar.tsx@@ -0,0 +1,99 @@+import { useEffect, useState } from "react";+import { supabaseClient } from "../utility/supabaseClient";++type TAvatarProps = {+ url?: string;+ size: number;+ onUpload: (filePath: string) => void;+};++export default function Avatar({+ url,+ size,+ onUpload,+}: TAvatarProps) {+ const [avatarUrl, setAvatarUrl] = useState("");+ const [uploading, setUploading] = useState(false);++ useEffect(() => {+ if (url) downloadImage(url);+ }, [url]);++ async function downloadImage(path: string) {+ try {+ const { data, error } = await supabaseClient.storage+ .from("avatars")+ .download(path);+ if (error) {+ throw error;+ }+ const url = URL.createObjectURL(data);+ setAvatarUrl(url);+ } catch (error: any) {+ console.log("Error downloading image: ", error?.message);+ }+ }++ async function uploadAvatar(event: React.ChangeEvent<HTMLInputElement>) {+ try {+ setUploading(true);++ if (!event.target.files || event.target.files.length === 0) {+ throw new Error("You must select an image to upload.");+ }++ const file = event.target.files[0];+ const fileExt = file.name.split(".").pop();+ const fileName = `${Math.random()}.${fileExt}`;+ const filePath = `${fileName}`;++ const { error: uploadError } = await supabaseClient.storage+ .from("avatars")+ .upload(filePath, file);++ if (uploadError) {+ throw uploadError;+ }+ onUpload(filePath);+ } catch (error: any) {+ alert(error.message);+ } finally {+ setUploading(false);+ }+ }++ return (+ <div>+ {avatarUrl ? (+ <img+ src={avatarUrl}+ alt="Avatar"+ className="avatar image"+ style={{ height: size, width: size }}+ />+ ) : (+ <div+ className="avatar no-image"+ style={{ height: size, width: size }}+ />+ )}+ <div style={{ width: size }}>+ <label className="button primary block" htmlFor="single">+ {uploading ? "Uploading ..." : "Upload"}+ </label>+ <input+ style={{+ visibility: "hidden",+ position: "absolute",+ }}+ type="file"+ id="single"+ name="avatar_url"+ accept="image/*"+ onChange={uploadAvatar}+ disabled={uploading}+ />+ </div>+ </div>+ );+};diff --git a/examples/user-management/refine-user-management/src/index.tsx b/examples/user-management/refine-user-management/src/index.tsxnew file mode 100644index 00000000000..8d978ffc882--- /dev/null+++ b/examples/user-management/refine-user-management/src/index.tsx@@ -0,0 +1,13 @@+import React from "react";+import { createRoot } from "react-dom/client";++import App from "./App";++const container = document.getElementById("root") as HTMLElement;+const root = createRoot(container);++root.render(+ <React.StrictMode>+ <App />+ </React.StrictMode>+);diff --git a/examples/user-management/refine-user-management/src/utility/index.ts b/examples/user-management/refine-user-management/src/utility/index.tsnew file mode 100644index 00000000000..1a21596513d--- /dev/null+++ b/examples/user-management/refine-user-management/src/utility/index.ts@@ -0,0 +1 @@+export * from "./supabaseClient";diff --git a/examples/user-management/refine-user-management/src/utility/supabaseClient.ts b/examples/user-management/refine-user-management/src/utility/supabaseClient.tsnew file mode 100644index 00000000000..d58cb40f1e4--- /dev/null+++ b/examples/user-management/refine-user-management/src/utility/supabaseClient.ts@@ -0,0 +1,14 @@+import { createClient } from "@refinedev/supabase";+++const supabaseUrl = import.meta.env.VITE_SUPABASE_URL;+const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY;++export const supabaseClient = createClient(supabaseUrl, supabaseAnonKey, {+ db: {+ schema: "public",+ },+ auth: {+ persistSession: true,+ },+});diff --git a/examples/user-management/refine-user-management/src/vite-env.d.ts b/examples/user-management/refine-user-management/src/vite-env.d.tsnew file mode 100644index 00000000000..11f02fe2a00--- /dev/null+++ b/examples/user-management/refine-user-management/src/vite-env.d.ts@@ -0,0 +1 @@+/// <reference types="vite/client" />diff --git a/examples/user-management/refine-user-management/tsconfig.json b/examples/user-management/refine-user-management/tsconfig.jsonnew file mode 100644index 00000000000..c132c6386c5--- /dev/null+++ b/examples/user-management/refine-user-management/tsconfig.json@@ -0,0 +1,25 @@+{+ "compilerOptions": {+ "target": "ESNext",+ "useDefineForClassFields": true,+ "lib": ["DOM", "DOM.Iterable", "ESNext"],+ "allowJs": false,+ "skipLibCheck": true,+ "esModuleInterop": false,+ "allowSyntheticDefaultImports": true,+ "strict": true,+ "forceConsistentCasingInFileNames": true,+ "module": "ESNext",+ "moduleResolution": "Node",+ "resolveJsonModule": true,+ "isolatedModules": true,+ "noEmit": true,+ "jsx": "react-jsx"+ },+ "include": ["src", "vite.config.ts"],+ "references": [+ {+ "path": "./tsconfig.node.json"+ }+ ]+}diff --git a/examples/user-management/refine-user-management/tsconfig.node.json b/examples/user-management/refine-user-management/tsconfig.node.jsonnew file mode 100644index 00000000000..bfa585014fc--- /dev/null+++ b/examples/user-management/refine-user-management/tsconfig.node.json@@ -0,0 +1,8 @@+{+ "compilerOptions": {+ "composite": true,+ "module": "ESNext",+ "moduleResolution": "node"+ },+ "include": ["vite.config.ts"]+}diff --git a/examples/user-management/refine-user-management/vite.config.ts b/examples/user-management/refine-user-management/vite.config.tsnew file mode 100644index 00000000000..58676f788a8--- /dev/null+++ b/examples/user-management/refine-user-management/vite.config.ts@@ -0,0 +1,6 @@+import react from "@vitejs/plugin-react";+import { defineConfig } from "vite";++export default defineConfig({+ plugins: [react()],+});