├── src
├── index.css
├── utils
│ └── config.js
├── store.js
├── routes
│ ├── ProtectedRoute.jsx
│ ├── ProfilePage.jsx
│ ├── PublicPage.jsx
│ ├── Redirect.jsx
│ └── AuthPage.jsx
├── components
│ ├── Spinner.jsx
│ └── ErrorPage.jsx
├── features
│ └── auth
│ │ ├── authService.js
│ │ └── authSlice.js
├── index.js
└── App.jsx
├── public
├── robots.txt
├── favicon.ico
├── logo192.png
├── manifest.json
└── index.html
├── postcss.config.js
├── tailwind.config.js
├── .gitignore
├── package.json
└── README.md
/src/index.css:
--------------------------------------------------------------------------------
1 | @tailwind base;
2 | @tailwind components;
3 | @tailwind utilities;
4 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rajesh6161/pocketbase-oauth-demo/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rajesh6161/pocketbase-oauth-demo/HEAD/public/logo192.png
--------------------------------------------------------------------------------
/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: {
3 | tailwindcss: {},
4 | autoprefixer: {},
5 | },
6 | }
7 |
--------------------------------------------------------------------------------
/src/utils/config.js:
--------------------------------------------------------------------------------
1 | import Pocketbase from 'pocketbase';
2 |
3 | const url = ' http://127.0.0.1:8090';
4 | const client = new Pocketbase(url);
5 |
6 | export { client };
7 |
--------------------------------------------------------------------------------
/tailwind.config.js:
--------------------------------------------------------------------------------
1 | /** @type {import('tailwindcss').Config} */
2 | module.exports = {
3 | content: ['./src/**/*.{js,jsx,ts,tsx}'],
4 | theme: {
5 | extend: {},
6 | },
7 | plugins: [require('@tailwindcss/forms')],
8 | };
9 |
--------------------------------------------------------------------------------
/src/store.js:
--------------------------------------------------------------------------------
1 | import { configureStore } from '@reduxjs/toolkit';
2 | import authReducer from './features/auth/authSlice';
3 |
4 | export const store = configureStore({
5 | middleware: (getDefaultMiddleware) => {
6 | return getDefaultMiddleware({
7 | serializableCheck: false,
8 | });
9 | },
10 | reducer: {
11 | auth: authReducer,
12 | },
13 | });
14 |
--------------------------------------------------------------------------------
/src/routes/ProtectedRoute.jsx:
--------------------------------------------------------------------------------
1 | import { useSelector } from 'react-redux';
2 | import { Navigate } from 'react-router-dom';
3 |
4 | const ProtectedRoute = ({ children }) => {
5 | const { loggedIn } = useSelector((state) => state.auth);
6 |
7 | if (!loggedIn) {
8 | return
Sorry, an unexpected error has occurred.
11 |12 | {error.statusText || error.message} 13 |
14 |19 | Welcome, {user?.meta?.name} 20 |
21 |Email: {user?.meta?.email}
22 | 23 |Back to root "/"
24 | 25 | 31 |12 | Currently:{' '} 13 | 18 | {loggedIn ? 'Logged In 🎉' : 'Not logged in 😔'} 19 | 20 |
21 |
22 | currently you are on "/" viz., a public page and if you try to access
23 | profile page you will be redirected to login page if you aren't logged
24 | in, as it is a protected route.
25 |
26 |
27 |
28 | Go to Profile "/profile"
29 |
30 | Authenticating...
34 | ) : ( 35 |
42 | Back to root "/"
47 | 48 | > 49 |Available Providers:
51 | {authProviders?.length > 0 && 52 | authProviders.map((provider) => ( 53 | oAuthHandler(provider)} 58 | > 59 | Login via {provider.name}{' '} 60 | 61 | ))} 62 | 63 | {authProviders?.length === 0 && ( 64 |No login methods available
65 | )} 66 |