Skip to content

Commit f1683d7

Browse files
authored
Merge pull request #246 from GBSL-Informatik/feature/better-auth
feature: use better-auth
2 parents a62e2ca + f74c918 commit f1683d7

File tree

46 files changed

+1360
-798
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1360
-798
lines changed

.env.example

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
CLIENT_ID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2-
TENANT_ID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
31
APP_URL="http://localhost:3000"
42
BACKEND_URL="http://localhost:3002"
5-
API_URI="api://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/access_as_user"
6-
STUDENT_USERNAME_PATTERN="@edu"
73
DEFAULT_TEST_USER="[email protected]"

.github/workflows/deploy.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ jobs:
2121
cache: yarn
2222
- name: Install dependencies and build website
2323
env:
24-
CLIENT_ID: ${{ secrets.CLIENT_ID }}
25-
TENANT_ID: ${{ secrets.TENANT_ID }}
26-
API_URI: ${{ secrets.API_URI }}
2724
APP_URL: ${{ secrets.APP_URL }}
2825
BACKEND_URL: ${{ secrets.BACKEND_URL }}
2926
GH_OAUTH_CLIENT_ID: ${{ vars.GH_OAUTH_CLIENT_ID}}

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ This website is built using [Docusaurus](https://docusaurus.io/), a modern stati
1111
| :------------------------- | :------------- | :---------------------------------- | :------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1212
| `APP_URL` | Production | `http://localhost:3000` | | Domain of the hosted app |
1313
| `BACKEND_URL` | Production | `http://localhost:3002` | | Url of the API Endpoint |
14-
| `CLIENT_ID` | Production | | | Azure ID: Client ID |
15-
| `TENANT_ID` | Production | | | Azure AD: Tenant Id |
16-
| `API_URI` | Production | | | Azure AD: API Url |
17-
| `STUDENT_USERNAME_PATTERN` | Production | | `@edu` | Users with usernames matching this RegExp pattern are displayed as students (regardless of admin status). If unset, all non-admin users are displayed as students. |
1814
| `DEFAULT_TEST_USER` | Development | | `[email protected]` | To log in offline. Email of the user to be selected by default. Must correspond to a user email found in the API's database.\* |
1915
| `OFFLINE_API` | Dev/Production | `memory` | `true` | `memory` | `indexedDB` | In case the project shall be fully functional, but API persistent data is not needed (e.g. when run in Github Codespace), set this option to true (=`memory`). |
2016
| `SENTRY_DSN` | Production | | | Sentry DSN for error tracking |

docs/tdev/app-architecture/api-deploy/index.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ page_id: 560cfd4d-4464-42ff-a121-a3d116ea1994
55
import Steps from '@tdev-components/Steps'
66
import { Val, TemplateCode, DynamicInput } from '@tdev-components/DynamicValues';
77
import _ from 'es-toolkit/compat';
8-
import { generateRandomBase64 } from './secureToken';
8+
import { generateRandomBase64 } from '../helpers/secureToken';
99

1010
# API Aufsetzen
1111

@@ -16,7 +16,6 @@ import { generateRandomBase64 } from './secureToken';
1616
<DynamicInput name="app" default='inf-teaching-api' />
1717
<DynamicInput name="domain" default='teaching-api.gbsl.website' />
1818
<DynamicInput name="APP_NAME" derived default={(page) => _.camelCase((page.dynamicValues.get('app') || 'inf-teaching-api'))} />
19-
<DynamicInput name="API_URI" placeholder='api://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' />
2019
<DynamicInput name="ALLOWED_ORIGINS" default='gbsl.website' />
2120
<DynamicInput name="ALLOW_SUBDOMAINS" default='true' />
2221
<DynamicInput name="SESSION_SECRET" monospace default='$(openssl rand -base64 32)' onRecalculate={() => generateRandomBase64()} />

docs/tdev/app-architecture/dokku/index.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ page_id: 323ff390-40d6-4bd5-ac6c-7a05f3515526
44

55
import Steps from '@tdev-components/Steps'
66
import { Val, TemplateCode, DynamicInput } from '@tdev-components/DynamicValues';
7+
import { generateRandomBase64 } from '../helpers/secureToken';
78

89
# Dokku Deploy
910

@@ -18,8 +19,8 @@ Durch das Hosten auf einem eigenen Server kann mit bspw. `http-auth` der Zugriff
1819
1. Eine neue App __<Val name="app" />__ auf dem Server erstellen
1920
<DynamicInput name="app" default='info-teaching-website' />
2021
<DynamicInput name="domain" default='info.gbsl.website' />
21-
<DynamicInput name="API_URI" default='api://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' />
22-
<DynamicInput name="BACKEND_URL" default='https://xxx-api.gbsl.website' />
22+
<DynamicInput name="BETTER_AUTH_URL" default='https://xxx-api.gbsl.website' />
23+
<DynamicInput name="BETTER_AUTH_SECRET" monospace default='$(openssl rand -base64 32)' onRecalculate={() => generateRandomBase64()} />
2324
<DynamicInput name="CLIENT_ID" default='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' />
2425
<DynamicInput name="TENANT_ID" default='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' />
2526
<TemplateCode>
@@ -34,7 +35,7 @@ Durch das Hosten auf einem eigenen Server kann mit bspw. `http-auth` der Zugriff
3435

3536
dokku config:set --no-restart {{app}} API_URI={{API_URI}}
3637
dokku config:set --no-restart {{app}} APP_URL=https://{{domain}}
37-
dokku config:set --no-restart {{app}} BACKEND_URL={{BACKEND_URL}}
38+
dokku config:set --no-restart {{app}} BETTER_AUTH_URL={{BETTER_AUTH_URL}}
3839
dokku config:set --no-restart {{app}} CLIENT_ID={{CLIENT_ID}}
3940
dokku config:set --no-restart {{app}} TENANT_ID={{TENANT_ID}}
4041
```
@@ -44,7 +45,7 @@ Durch das Hosten auf einem eigenen Server kann mit bspw. `http-auth` der Zugriff
4445
```bash title="/home/dokku/{{app}}/ENV"
4546
API_URI="{{API_URI}}"
4647
APP_URL="https://{{domain}}"
47-
BACKEND_URL="{{BACKEND_URL}}"
48+
BETTER_AUTH_URL="{{BETTER_AUTH_URL}}"
4849
CLIENT_ID="{{CLIENT_ID}}"
4950
TENANT_ID="{{TENANT_ID}}"
5051
NGINX_ROOT="build"

docusaurus.config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ const config: Config = applyTransformers({
7171
/** Use test user in local dev: set DEFAULT_TEST_USER to the default test users email adress*/
7272
TEST_USER: DEFAULT_TEST_USER,
7373
OFFLINE_API: OFFLINE_API,
74-
/** User.ts#isStudent returns `true` for users matching this pattern. If unset, it returns `true` for all non-admin users. */
75-
STUDENT_USERNAME_PATTERN: process.env.STUDENT_USERNAME_PATTERN,
7674
NO_AUTH: (process.env.NODE_ENV !== 'production' || OFFLINE_API) && !!DEFAULT_TEST_USER,
7775
/** The Domain Name where the api is running */
7876
APP_URL: process.env.NETLIFY
@@ -82,12 +80,6 @@ const config: Config = applyTransformers({
8280
: process.env.APP_URL || 'http://localhost:3000',
8381
/** The Domain Name of this app */
8482
BACKEND_URL: process.env.BACKEND_URL || 'http://localhost:3002',
85-
/** The application id generated in https://portal.azure.com */
86-
CLIENT_ID: process.env.CLIENT_ID,
87-
/** Tenant / Verzeichnis-ID (Mandant) */
88-
TENANT_ID: process.env.TENANT_ID,
89-
/** The application id uri generated in https://portal.azure.com */
90-
API_URI: process.env.API_URI,
9183
GIT_COMMIT_SHA: GIT_COMMIT_SHA,
9284
SENTRY_DSN: process.env.SENTRY_DSN,
9385
GH_OAUTH_CLIENT_ID: GH_OAUTH_CLIENT_ID,

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
"updateTdev": "ts-node updateSync/updateTdev.ts"
2424
},
2525
"dependencies": {
26-
"@azure/msal-browser": "^v3.28.0",
27-
"@azure/msal-react": "^2.2.0",
2826
"@docusaurus/core": "^3.8.1",
2927
"@docusaurus/faster": "^3.8.1",
3028
"@docusaurus/preset-classic": "^3.8.1",
@@ -49,6 +47,7 @@
4947
"@sentry/webpack-plugin": "^3.3.1",
5048
"ace-builds": "^1.41.0",
5149
"axios": "^1.9.0",
50+
"better-auth": "^1.3.26",
5251
"browser-image-compression": "^2.0.2",
5352
"clsx": "^2.1.1",
5453
"docusaurus-plugin-sass": "^0.2.6",

src/api/OfflineApi/Adapter/MemoryDb.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class MemoryDbAdapter implements DbAdapter {
1111

1212
async getAll<T>(storeName: string): Promise<T[]> {
1313
if (!this.db[storeName]) {
14-
return [];
14+
return Promise.resolve([]);
1515
}
16-
return Object.values(this.db[storeName]) as T[];
16+
return Promise.resolve(Object.values(this.db[storeName]) as T[]);
1717
}
1818

1919
async byDocumentRootId<T extends DocumentType>(
@@ -22,31 +22,34 @@ class MemoryDbAdapter implements DbAdapter {
2222
if (!documentRootId) {
2323
return Promise.resolve([]);
2424
}
25-
return this.filter('documents', (doc) => doc.documentRootId === documentRootId) as Promise<
26-
Document<T>[]
27-
>;
25+
return Promise.resolve(
26+
this.filter('documents', (doc) => doc.documentRootId === documentRootId) as Promise<Document<T>[]>
27+
);
2828
}
2929

3030
async put<T>(storeName: string, item: T & { id: string }): Promise<void> {
3131
if (!this.db[storeName]) {
3232
this.db[storeName] = {};
3333
}
3434
this.db[storeName][item.id] = item;
35+
return Promise.resolve();
3536
}
3637

3738
async delete(storeName: string, id: string): Promise<void> {
3839
if (this.db[storeName] && this.db[storeName][id]) {
3940
delete this.db[storeName][id];
4041
}
42+
return Promise.resolve();
4143
}
4244
async filter<T>(storeName: string, filterFn: (item: T) => boolean): Promise<T[]> {
4345
const allItems = await this.getAll<T>(storeName);
44-
return allItems.filter(filterFn);
46+
return Promise.resolve(allItems.filter(filterFn));
4547
}
4648

4749
async destroyDb(): Promise<void> {
4850
this.db = {};
4951
console.log('MemoryDbAdapter: Database destroyed');
52+
return Promise.resolve();
5053
}
5154
}
5255

src/api/OfflineApi/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const LOG_REQUESTS = false;
1818
let OfflineUser: User = {
1919
id: 'c23c0238-4aeb-457f-9a2c-3d2d5d8931c0',
2020
21+
name: 'Offline User',
2122
firstName: 'Offline',
2223
lastName: 'User',
2324
role: process.env.NODE_ENV === 'production' ? Role.STUDENT : Role.ADMIN,
@@ -29,6 +30,7 @@ const DB_NAME = `${siteConfig.organizationName ?? 'gbsl'}-${siteConfig.projectNa
2930
const DOCUMENTS_STORE = 'documents';
3031
const STUDENT_GROUPS_STORE = 'studentGroups';
3132
const PERMISSIONS_STORE = 'permissions';
33+
export const getOfflineUser = () => ({ ...OfflineUser });
3234

3335
const resolveResponse = <T>(data: T, statusCode: number = 200, statusText: string = ''): AxiosPromise<T> => {
3436
return Promise.resolve({
@@ -90,6 +92,7 @@ export default class OfflineApi {
9092
this.dbAdapter = new MemoryDbAdapter();
9193
}
9294
} else {
95+
console.log('setup memory adapter');
9396
this.dbAdapter = new MemoryDbAdapter();
9497
}
9598
if (LOG_REQUESTS) {
@@ -236,8 +239,6 @@ export default class OfflineApi {
236239
return resolveResponse([] as unknown as T);
237240
case 'allowedActions':
238241
return resolveResponse([] as unknown as T);
239-
case 'checklogin':
240-
return resolveResponse({ user: OfflineUser } as unknown as T, 200, 'ok');
241242
case 'documents':
242243
if (id) {
243244
const document = await this.dbAdapter.get<Document<any>>(DOCUMENTS_STORE, id);

0 commit comments

Comments
 (0)