├── src ├── App.css ├── react-app-env.d.ts ├── styles │ ├── BlogPost.module.css │ ├── MainNavigation.module.css │ ├── BlogActions.module.css │ ├── Posts.module.css │ └── NewPostForm.module.css ├── components │ ├── BlogPost.tsx │ ├── RootLayout.tsx │ ├── BlogActions.tsx │ ├── ProtectedRoute.tsx │ ├── Posts.tsx │ ├── MainNavigation.tsx │ └── NewPostForm.tsx ├── setupTests.ts ├── config │ └── supabase-client.ts ├── pages │ ├── BlogLayout.tsx │ ├── WelcomePage.tsx │ ├── BlogPosts.tsx │ ├── PostDetail.tsx │ ├── NewPost.tsx │ └── Login.tsx ├── App.test.tsx ├── index.css ├── reportWebVitals.ts ├── index.tsx ├── api │ └── posts.ts ├── App.tsx ├── hooks │ └── Auth.tsx └── logo.svg ├── public ├── robots.txt ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── .gitignore ├── tsconfig.json ├── package.json └── README.md /src/App.css: -------------------------------------------------------------------------------- 1 | @import '~rsuite/dist/rsuite.min.css'; 2 | -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellaera/react-supabase-auth-provider/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellaera/react-supabase-auth-provider/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daniellaera/react-supabase-auth-provider/HEAD/public/logo512.png -------------------------------------------------------------------------------- /src/styles/BlogPost.module.css: -------------------------------------------------------------------------------- 1 | .post { 2 | margin: 2rem auto; 3 | max-width: 40rem; 4 | text-align: center; 5 | text-transform: capitalize; 6 | } -------------------------------------------------------------------------------- /src/components/BlogPost.tsx: -------------------------------------------------------------------------------- 1 | function BlogPost({ title, text }: any) { 2 | return ( 3 |
4 |

{title}

5 |

{text}

6 |
7 | ); 8 | } 9 | 10 | export default BlogPost; 11 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/config/supabase-client.ts: -------------------------------------------------------------------------------- 1 | import { createClient } from '@supabase/supabase-js'; 2 | 3 | const supabaseUrl: string = process.env.REACT_APP_SUPABASE_URL!; 4 | const supabaseAnonKey: string = process.env.REACT_APP_SUPABASE_ANON_KEY!; 5 | 6 | export const supabaseClient = createClient(supabaseUrl, supabaseAnonKey); -------------------------------------------------------------------------------- /src/pages/BlogLayout.tsx: -------------------------------------------------------------------------------- 1 | import { Outlet } from 'react-router-dom'; 2 | 3 | import BlogActions from '../components/BlogActions'; 4 | 5 | function BlogLayout() { 6 | return ( 7 | <> 8 | 9 | 10 | 11 | ); 12 | } 13 | 14 | export default BlogLayout; 15 | -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/components/RootLayout.tsx: -------------------------------------------------------------------------------- 1 | import { ReactNode } from 'react'; 2 | import MainNavigation from './MainNavigation'; 3 | 4 | function RootLayout({ children }: {children: ReactNode}) { 5 | return ( 6 | <> 7 | 8 |
{children}
9 | 10 | ); 11 | } 12 | 13 | export default RootLayout; -------------------------------------------------------------------------------- /src/styles/MainNavigation.module.css: -------------------------------------------------------------------------------- 1 | .header { 2 | padding: 2rem; 3 | } 4 | 5 | .header ul { 6 | display: flex; 7 | gap: 2rem; 8 | justify-content: center; 9 | } 10 | 11 | .header a { 12 | color: #e5e5e5; 13 | font-size: 1.15rem; 14 | text-decoration: none; 15 | } 16 | 17 | .header a:hover, 18 | .header a:active, 19 | .header a.active { 20 | color: #fcb66b; 21 | } 22 | -------------------------------------------------------------------------------- /src/styles/BlogActions.module.css: -------------------------------------------------------------------------------- 1 | .actions { 2 | display: flex; 3 | justify-content: center; 4 | max-width: 30rem; 5 | margin: 2rem auto; 6 | } 7 | 8 | .button { 9 | font: inherit; 10 | background-color: #e5e5e5; 11 | color: #343232; 12 | border-radius: 4px; 13 | padding: 0.5rem 1.5rem; 14 | text-decoration: none; 15 | } 16 | 17 | .button:hover { 18 | background-color: #f9d3a9; 19 | } -------------------------------------------------------------------------------- /src/components/BlogActions.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from 'react-router-dom'; 2 | import { Button , Stack} from 'rsuite'; 3 | 4 | function BlogActions() { 5 | return ( 6 | 7 | 8 | 9 | ); 10 | } 11 | 12 | export default BlogActions; 13 | -------------------------------------------------------------------------------- /src/components/ProtectedRoute.tsx: -------------------------------------------------------------------------------- 1 | import { Navigate } from "react-router-dom"; 2 | import { useAuth } from "../hooks/Auth"; 3 | 4 | const ProtectedRoute = ({ children }: any) => { 5 | const { user } = useAuth() 6 | 7 | if (!user) { 8 | // user is not authenticated 9 | return ; 10 | } 11 | return <>{children} 12 | }; 13 | 14 | export default ProtectedRoute -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /src/components/Posts.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from 'react-router-dom'; 2 | import { List, FlexboxGrid } from 'rsuite'; 3 | 4 | function Posts({ blogPosts }: any) { 5 | return ( 6 | 7 | {blogPosts.map((post: any) => ( 8 | 9 | 10 |

{post.title}

11 | 12 |
13 | ))} 14 |
15 | ); 16 | } 17 | 18 | export default Posts; 19 | -------------------------------------------------------------------------------- /src/styles/Posts.module.css: -------------------------------------------------------------------------------- 1 | .posts { 2 | display: flex; 3 | flex-direction: column; 4 | gap: 1.5rem; 5 | max-width: 40rem; 6 | margin: 2rem auto; 7 | } 8 | 9 | .posts h2 { 10 | text-transform: capitalize; 11 | font-size: 1.15rem; 12 | font-weight: normal; 13 | } 14 | 15 | .posts a { 16 | border-radius: 4px; 17 | padding: 1rem; 18 | background-color: #343232; 19 | text-decoration: none; 20 | color: inherit; 21 | display: block; 22 | } 23 | 24 | .posts a:hover { 25 | background-color: #665a4d; 26 | } 27 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot( 8 | document.getElementById('root') as HTMLElement 9 | ); 10 | root.render( 11 | 12 | 13 | 14 | ); 15 | 16 | // If you want to start measuring performance in your app, pass a function 17 | // to log results (for example: reportWebVitals(console.log)) 18 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 19 | reportWebVitals(); 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src", 25 | "config-overrides.js" 26 | ] 27 | } -------------------------------------------------------------------------------- /src/pages/WelcomePage.tsx: -------------------------------------------------------------------------------- 1 | import { Panel, Stack } from 'rsuite'; 2 | 3 | function WelcomePage() { 4 | return ( 5 | 6 | 7 | 8 | 9 |

10 | 11 | A suite of React components, sensible UI design, and a friendly development experience. 12 | 13 |

14 |
15 |
16 |
17 | ); 18 | } 19 | 20 | export default WelcomePage; 21 | -------------------------------------------------------------------------------- /src/pages/BlogPosts.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react'; 2 | import { getPosts } from '../api/posts'; 3 | import { Loader, Stack} from 'rsuite'; 4 | import Posts from '../components/Posts'; 5 | 6 | function BlogPostsPage() { 7 | const [error, setError] = useState(); 8 | const [posts, setPosts] = useState(); 9 | const [isLoading, setIsLoading] = useState(false); 10 | 11 | useEffect(() => { 12 | async function loadPosts() { 13 | setIsLoading(true); 14 | try { 15 | const posts = await getPosts(); 16 | setPosts(posts); 17 | } catch (err: any) { 18 | setError(err.message); 19 | } 20 | setIsLoading(false); 21 | } 22 | 23 | loadPosts(); 24 | }, []); 25 | 26 | return ( 27 | 28 |

Our Blog Posts

29 | {isLoading && } 30 | {error &&

{error}

} 31 | {!error && posts && } 32 |
33 | ); 34 | } 35 | 36 | export default BlogPostsPage; -------------------------------------------------------------------------------- /src/api/posts.ts: -------------------------------------------------------------------------------- 1 | export async function getPosts() { 2 | const response = await fetch('https://jsonplaceholder.typicode.com/posts'); 3 | if (!response.ok) { 4 | throw new Error("Failed to fetch posts"); 5 | } 6 | return response.json(); 7 | } 8 | 9 | export async function getPost(id: any) { 10 | const response = await fetch( 11 | 'https://jsonplaceholder.typicode.com/posts/' + id 12 | ); 13 | if (!response.ok) { 14 | throw new Error("Failed to fetch posts"); 15 | } 16 | return response.json(); 17 | } 18 | 19 | export async function savePost(post: any) { 20 | if (post.title.trim().length < 5 || post.body.trim().length < 10) { 21 | throw new Error('Invalid input data provided.'); 22 | } 23 | 24 | const response = await fetch('https://jsonplaceholder.typicode.com/posts', { 25 | method: 'POST', 26 | body: JSON.stringify(post), 27 | headers: { 28 | 'Content-Type': 'application/json', 29 | }, 30 | }); 31 | 32 | if (!response.ok) { 33 | throw new Error("Could not save post"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/styles/NewPostForm.module.css: -------------------------------------------------------------------------------- 1 | .form { 2 | margin: 2rem auto; 3 | max-width: 20rem; 4 | } 5 | 6 | .form fieldset { 7 | border: none; 8 | margin: 0.5rem 0; 9 | } 10 | 11 | .form input, 12 | .form label, 13 | .form textarea { 14 | font: inherit; 15 | display: block; 16 | } 17 | 18 | .form input, 19 | .form textarea { 20 | width: 100%; 21 | border-radius: 4px; 22 | padding: 0.5rem; 23 | } 24 | 25 | .form label { 26 | font-weight: bold; 27 | margin-bottom: 0.5rem; 28 | } 29 | 30 | .form button { 31 | font: inherit; 32 | padding: 0.5rem 1.5rem; 33 | border-radius: 4px; 34 | border: none; 35 | cursor: pointer; 36 | background-color: #e5e3e3; 37 | } 38 | 39 | .form button:hover { 40 | background-color: #fcb66b; 41 | } 42 | 43 | .form button[type='button'] { 44 | background-color: transparent; 45 | color: #c7c4c4; 46 | } 47 | 48 | .form button[type='button']:hover { 49 | color: #fcb66b; 50 | } 51 | 52 | .form button:disabled { 53 | background-color: #a2a1a1; 54 | color: #515151; 55 | } 56 | 57 | .form button[type='button']:disabled { 58 | color: #515151; 59 | background-color: transparent; 60 | } -------------------------------------------------------------------------------- /src/pages/PostDetail.tsx: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from 'react'; 2 | import { useParams } from 'react-router-dom'; 3 | import { Loader, Stack } from 'rsuite'; 4 | import { getPost } from '../api/posts'; 5 | 6 | import BlogPost from '../components/BlogPost'; 7 | 8 | function PostDetailPage() { 9 | const [error, setError] = useState(); 10 | const [post, setPost] = useState(); 11 | const [isLoading, setIsLoading] = useState(false); 12 | 13 | const params = useParams(); 14 | const { id } = params; 15 | 16 | useEffect(() => { 17 | async function loadPost() { 18 | setIsLoading(true); 19 | try { 20 | const post = await getPost(id); 21 | setPost(post); 22 | } catch (err: any) { 23 | setError(err.message); 24 | } 25 | setIsLoading(false); 26 | } 27 | 28 | loadPost(); 29 | }, [id]); 30 | 31 | return ( 32 | 33 | {isLoading && } 34 | {error &&

{error.message}

} 35 | {!error && post && } 36 |
37 | ); 38 | } 39 | 40 | export default PostDetailPage; -------------------------------------------------------------------------------- /src/components/MainNavigation.tsx: -------------------------------------------------------------------------------- 1 | import { NavLink } from 'react-router-dom'; 2 | import { IconButton, Nav, Navbar, Tag } from 'rsuite'; 3 | import HomeIcon from '@rsuite/icons/legacy/Home'; 4 | import { useAuth } from '../hooks/Auth'; 5 | import OffRoundIcon from '@rsuite/icons/OffRound'; 6 | import AdminIcon from '@rsuite/icons/Admin'; 7 | 8 | function MainNavigation() { 9 | const { user } = useAuth() 10 | const { signOut } = useAuth() 11 | 12 | const handleLogout = () => { 13 | signOut() 14 | } 15 | return ( 16 | 17 | 30 | 33 | 34 | ); 35 | } 36 | 37 | export default MainNavigation; 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-router-6.6.2-boilerplate", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@supabase/supabase-js": "^2.5.0", 7 | "@testing-library/jest-dom": "^5.16.5", 8 | "@testing-library/react": "^13.4.0", 9 | "@testing-library/user-event": "^13.5.0", 10 | "@types/jest": "^27.5.2", 11 | "@types/node": "^16.18.11", 12 | "@types/react": "^18.0.26", 13 | "@types/react-dom": "^18.0.10", 14 | "react": "^18.2.0", 15 | "react-dom": "^18.2.0", 16 | "react-icons": "^4.7.1", 17 | "react-router-dom": "^6.6.2", 18 | "react-scripts": "5.0.1", 19 | "rsuite": "^5.24.1", 20 | "typescript": "^4.9.4", 21 | "web-vitals": "^2.1.4" 22 | }, 23 | "scripts": { 24 | "start": "react-scripts start", 25 | "build": "react-scripts build", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": [ 31 | "react-app", 32 | "react-app/jest" 33 | ] 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/pages/NewPost.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from 'react'; 2 | import { useNavigate } from 'react-router-dom'; 3 | import { Stack } from 'rsuite'; 4 | import { savePost } from '../api/posts'; 5 | 6 | import NewPostForm from '../components/NewPostForm'; 7 | 8 | function NewPostPage() { 9 | const [isSubmitting, setIsSubmitting] = useState(false); 10 | const [error, setError] = useState(); 11 | const navigate = useNavigate(); 12 | 13 | async function submitHandler(event: any) { 14 | event.preventDefault(); 15 | setIsSubmitting(true); 16 | try { 17 | const formData = new FormData(event.target); 18 | const post = { 19 | title: formData.get('title'), 20 | body: formData.get('post-text'), 21 | }; 22 | await savePost(post); 23 | navigate('/'); 24 | } catch (err: any) { 25 | setError(err); 26 | } 27 | setIsSubmitting(false); 28 | } 29 | 30 | function cancelHandler() { 31 | navigate('/blog'); 32 | } 33 | 34 | return ( 35 | 36 | {error &&

{error.message}

} 37 | 42 |
43 | ); 44 | } 45 | 46 | export default NewPostPage; 47 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import { BrowserRouter, Route, Routes } from 'react-router-dom'; 2 | import RootLayout from './components/RootLayout'; 3 | import BlogLayout from './pages/BlogLayout'; 4 | import BlogPostsPage from './pages/BlogPosts'; 5 | import NewPostPage from './pages/NewPost'; 6 | import PostDetailPage from './pages/PostDetail'; 7 | import WelcomePage from './pages/WelcomePage'; 8 | import './App.css'; 9 | import { CustomProvider } from 'rsuite'; 10 | import Login from './pages/Login'; 11 | import ProtectedRoute from './components/ProtectedRoute'; 12 | import { AuthProvider } from './hooks/Auth'; 13 | 14 | function App() { 15 | return ( 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | } 28 | /> 29 | } /> 30 | 34 | 35 | 36 | } 37 | > 38 | } /> 39 | } /> 40 | 41 | } /> 42 | 43 | 44 | 45 | 46 | 47 | ); 48 | } 49 | 50 | export default App; 51 | -------------------------------------------------------------------------------- /src/hooks/Auth.tsx: -------------------------------------------------------------------------------- 1 | import { Session, User } from '@supabase/supabase-js'; 2 | import { useContext, useState, useEffect, createContext } from 'react'; 3 | import { supabaseClient } from '../config/supabase-client'; 4 | 5 | // create a context for authentication 6 | const AuthContext = createContext<{ session: Session | null | undefined, user: User | null | undefined, signOut: () => void }>({ session: null, user: null, signOut: () => {} }); 7 | 8 | export const AuthProvider = ({ children }: any) => { 9 | const [user, setUser] = useState() 10 | const [session, setSession] = useState(); 11 | const [loading, setLoading] = useState(true); 12 | 13 | useEffect(() => { 14 | const setData = async () => { 15 | const { data: { session }, error } = await supabaseClient.auth.getSession(); 16 | if (error) throw error; 17 | setSession(session) 18 | setUser(session?.user) 19 | setLoading(false); 20 | }; 21 | 22 | const { data: listener } = supabaseClient.auth.onAuthStateChange((_event, session) => { 23 | setSession(session); 24 | setUser(session?.user) 25 | setLoading(false) 26 | }); 27 | 28 | setData(); 29 | 30 | return () => { 31 | listener?.subscription.unsubscribe(); 32 | }; 33 | }, []); 34 | 35 | const value = { 36 | session, 37 | user, 38 | signOut: () => supabaseClient.auth.signOut(), 39 | }; 40 | 41 | // use a provider to pass down the value 42 | return ( 43 | 44 | {!loading && children} 45 | 46 | ); 47 | }; 48 | 49 | // export the useAuth hook 50 | export const useAuth = () => { 51 | return useContext(AuthContext); 52 | }; -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/components/NewPostForm.tsx: -------------------------------------------------------------------------------- 1 | import { forwardRef } from 'react'; 2 | import { Form, ButtonToolbar, Button, Input } from 'rsuite'; 3 | 4 | const Textarea = forwardRef((props, ref: any) => ); 5 | 6 | function NewPostForm({ onCancel, onSubmit, submitting }: any) { 7 | return ( 8 | /*
9 |
10 | 11 | 12 |
13 |
14 | 15 | 22 |
23 | 26 | 29 |
*/ 30 |
31 | 32 | title 33 | 34 | title is required 35 | 36 | 37 | content 38 | 39 | content is required 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
48 | ) 49 | 50 | } 51 | 52 | export default NewPostForm; 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/pages/Login.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react'; 2 | import { 3 | Container, 4 | Content, 5 | Form, 6 | ButtonToolbar, 7 | Button, 8 | Panel, 9 | FlexboxGrid, 10 | Loader, 11 | IconButton 12 | } from 'rsuite'; 13 | import { supabaseClient } from '../config/supabase-client'; 14 | import { Session } from '@supabase/supabase-js'; 15 | import OffRoundIcon from '@rsuite/icons/OffRound'; 16 | import { useNavigate } from 'react-router-dom'; 17 | 18 | function Login() { 19 | const [email, setEmail] = useState('') 20 | const [password, setPassword] = useState('') 21 | const [session, setSession] = useState() 22 | const [loading, setLoading] = useState(false); 23 | const navigate = useNavigate(); 24 | 25 | useEffect(() => { 26 | supabaseClient.auth.getSession().then(({ data: { session } }) => { 27 | setSession(session) 28 | }) 29 | 30 | supabaseClient.auth.onAuthStateChange((_event, session) => { 31 | setSession(session) 32 | }) 33 | }, []) 34 | 35 | const Login = async () => { 36 | setLoading(true); 37 | try { 38 | const { error } = await supabaseClient.auth.signInWithPassword({ 39 | email, 40 | password 41 | }) 42 | if (error) throw error 43 | navigate("/"); 44 | } catch (err) { 45 | throw err; 46 | } finally { 47 | setEmail('') 48 | setPassword('') 49 | setLoading(false); 50 | } 51 | } 52 | 53 | const Logout = async () => { 54 | const { error } = await supabaseClient.auth.signOut() 55 | if (error) throw error 56 | } 57 | 58 | if (loading) return 59 | 60 | return ( 61 | 62 | 63 | 64 | 65 | { 66 | !session ? <> 67 | Login} shaded bordered style={{ width: 500, margin: '0 auto'}}> 68 |
69 | 70 | Username or email address 71 | setEmail(e)} /> 72 | 73 | 74 | Password 75 | setPassword(e)} name="password" type="password" autoComplete="off" /> 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 |
85 | : <> 86 |

Welcome back {session.user.email}

87 | }>Logout 88 | 89 | } 90 |
91 |
92 |
93 |
94 | ); 95 | } 96 | 97 | export default Login; 98 | --------------------------------------------------------------------------------