|
| 1 | +# Contributing to Seamless Auth |
| 2 | + |
| 3 | +Thank you for contributing to Seamless Auth. |
| 4 | + |
| 5 | +## Philosophy |
| 6 | + |
| 7 | +Seamless Auth is: |
| 8 | + |
| 9 | +- Passwordless-first |
| 10 | +- Security-focused |
| 11 | +- Minimal and intentional |
| 12 | +- Infrastructure-grade software |
| 13 | + |
| 14 | +## Before You Start |
| 15 | + |
| 16 | +For non-trivial changes: |
| 17 | + |
| 18 | +1. Open an issue first |
| 19 | +2. Explain the motivation |
| 20 | +3. Describe your proposed solution |
| 21 | +4. Wait for feedback |
| 22 | + |
| 23 | +## Development Setup (React SDK) |
| 24 | + |
| 25 | +The React SDK is developed against a real Seamless Auth server instance. |
| 26 | + |
| 27 | +Contributors must run the local Seamless Auth server while developing changes to this package. |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## 1. Fork and Clone |
| 32 | + |
| 33 | +Fork the repository and clone it locally: |
| 34 | + |
| 35 | +```bash |
| 36 | +# Clone the auth server code or your forks |
| 37 | +git clone https://github.com/fells-code/seamless-auth-api.git |
| 38 | + |
| 39 | +# Clone the react SDK |
| 40 | +git clone https://github.com/fells-code/seamless-auth-react.git |
| 41 | +``` |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## 2. Run the Seamless Auth Server |
| 46 | + |
| 47 | +```bash |
| 48 | +cd seamless-auth-api |
| 49 | +cp .env.example .env |
| 50 | +``` |
| 51 | + |
| 52 | +> IMPORTANT |
| 53 | +> Change the AUTH_MODE env to "web" NOT "server". |
| 54 | +> Change the APP_ORIGIN env to `http://localhost:5173` to match vite |
| 55 | +> This lets you authenticate between a web app and the auth server with no need for an API. |
| 56 | +
|
| 57 | +### If docker and docker compose are avaliable |
| 58 | + |
| 59 | +```bash |
| 60 | +docker compose up -d |
| 61 | +``` |
| 62 | + |
| 63 | +> If you are using docker you can stop here and move on to Step 3. |
| 64 | +
|
| 65 | +### If not using docker |
| 66 | + |
| 67 | +Start postgres in whatever way your system does e.g. on mac |
| 68 | + |
| 69 | +```bash |
| 70 | +brew services start postgresql |
| 71 | +``` |
| 72 | + |
| 73 | +### Prepare the database |
| 74 | + |
| 75 | +```bash |
| 76 | +npm install |
| 77 | + |
| 78 | +npm run db:create |
| 79 | +npm run db:migrate |
| 80 | + |
| 81 | +npm run dev |
| 82 | +``` |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +Ensure the server is running locally (default: `http://localhost:5312`). |
| 87 | + |
| 88 | +```bash |
| 89 | +curl http://localhost:5312/health/status |
| 90 | + |
| 91 | +## Expected result |
| 92 | +## {"message":"System up"} |
| 93 | +``` |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## 3. Create a Local Test Application |
| 98 | + |
| 99 | +You will need a web application to integerate the SDK into. |
| 100 | +We recommend using Vite for fast iteration: |
| 101 | + |
| 102 | +```bash |
| 103 | +# If still in the auth directory |
| 104 | +cd ../ |
| 105 | + |
| 106 | +npm create vite@latest seamless-auth-dev |
| 107 | +### Select React as the framework, Typescript as the variant |
| 108 | +``` |
| 109 | + |
| 110 | +> Web site will be active at http://localhost:5137 |
| 111 | +
|
| 112 | +--- |
| 113 | + |
| 114 | +## 4. Link the React Package |
| 115 | + |
| 116 | +From the `seamless-auth-react` repository: |
| 117 | + |
| 118 | +```bash |
| 119 | +npm install |
| 120 | +npm link |
| 121 | +``` |
| 122 | + |
| 123 | +Then inside your test application: |
| 124 | + |
| 125 | +```bash |
| 126 | +npm link @seamless-auth/react |
| 127 | +npm install react-router-dom |
| 128 | +``` |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +## 5. Wrap Your Application with AuthProvider |
| 133 | + |
| 134 | +Update `main.tsx`: |
| 135 | + |
| 136 | +```tsx |
| 137 | +// main.tsx |
| 138 | +import { StrictMode } from 'react'; |
| 139 | +import { createRoot } from 'react-dom/client'; |
| 140 | +import { AuthProvider, AuthRoutes, useAuth } from '@seamless-auth/react'; |
| 141 | +import './index.css'; |
| 142 | +import App from './App.tsx'; |
| 143 | +import { BrowserRouter, Route, Routes } from 'react-router-dom'; |
| 144 | + |
| 145 | +// eslint-disable-next-line react-refresh/only-export-components |
| 146 | +function ApplicationRoutes() { |
| 147 | + const { isAuthenticated } = useAuth(); |
| 148 | + |
| 149 | + return ( |
| 150 | + <Routes> |
| 151 | + {isAuthenticated ? ( |
| 152 | + <Route path="*" element={<App />} /> |
| 153 | + ) : ( |
| 154 | + <Route path="*" element={<AuthRoutes />} /> |
| 155 | + )} |
| 156 | + </Routes> |
| 157 | + ); |
| 158 | +} |
| 159 | + |
| 160 | +createRoot(document.getElementById('root')!).render( |
| 161 | + <StrictMode> |
| 162 | + <BrowserRouter> |
| 163 | + <AuthProvider apiHost="http://localhost:5312" mode="web"> |
| 164 | + <ApplicationRoutes /> |
| 165 | + </AuthProvider> |
| 166 | + </BrowserRouter> |
| 167 | + </StrictMode> |
| 168 | +); |
| 169 | +``` |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## 6. Run the SDK in Watch Mode |
| 174 | + |
| 175 | +Inside `seamless-auth-react`: |
| 176 | + |
| 177 | +```bash |
| 178 | +npm run build -- --watch |
| 179 | +``` |
| 180 | + |
| 181 | +Changes will automatically rebuild and propagate to your linked development application. |
| 182 | + |
| 183 | +## 7. Good working state |
| 184 | + |
| 185 | +If all went well you should have a directory structure like this |
| 186 | + |
| 187 | +```bash |
| 188 | +. |
| 189 | +├── seamless-auth-api |
| 190 | +├── seamless-auth-dev |
| 191 | +└── seamless-auth-react |
| 192 | +``` |
| 193 | + |
| 194 | +Navigating to `http://localhost:5173` give you the seamless auth login page. |
| 195 | + |
| 196 | +If so you are ready to start dev work |
| 197 | + |
| 198 | +## Expectations |
| 199 | + |
| 200 | +When submitting a pull request: |
| 201 | + |
| 202 | +- Ensure the SDK works against a running local auth server |
| 203 | +- Verify login, logout, and session behavior |
| 204 | +- Confirm role-based logic works as expected |
| 205 | +- Run lint and tests before submitting |
| 206 | + |
| 207 | +This ensures changes remain aligned with real authentication flows and infrastructure behavior. |
| 208 | + |
| 209 | +## Commit Conventions |
| 210 | + |
| 211 | +- feat: |
| 212 | +- fix: |
| 213 | +- docs: |
| 214 | +- refactor: |
| 215 | +- test: |
| 216 | +- chore: |
| 217 | + |
| 218 | +Example: |
| 219 | + |
| 220 | +feat: add configurable token expiration override |
| 221 | + |
| 222 | +## Pull Requests Must |
| 223 | + |
| 224 | +- Be scoped |
| 225 | +- Include tests |
| 226 | +- Update docs |
| 227 | +- Pass CI |
| 228 | + |
| 229 | +## Licensing |
| 230 | + |
| 231 | +By contributing, you agree your contributions fall under the project license. |
0 commit comments