Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(auth): enable demo mode authentication with createDemoAuthClient (#73)

Corentin THOMASSET2a4731c0d7e7
diff --git a/apps/papra-client/src/modules/auth/auth.demo.services.ts b/apps/papra-client/src/modules/auth/auth.demo.services.ts
new file mode 100644
index 00000000..c6832e94
--- /dev/null
+++ b/apps/papra-client/src/modules/auth/auth.demo.services.ts
@@ -0,0 +1,20 @@
+import type { createAuthClient } from 'better-auth/solid';
+
+export function createDemoAuthClient() {
+ return {
+ useSession: () => () => ({
+ isPending: false,
+ data: {
+ user: {
+ id: '1',
+ email: '[email protected]',
+ },
+ },
+ }),
+ signIn: {
+ email: () => Promise.resolve({}),
+ social: () => Promise.resolve({}),
+ },
+ signOut: () => Promise.resolve({}),
+ } as unknown as ReturnType<typeof createAuthClient>;
+}
diff --git a/apps/papra-client/src/modules/auth/auth.services.ts b/apps/papra-client/src/modules/auth/auth.services.ts
index 5978a806..7959ea0e 100644
--- a/apps/papra-client/src/modules/auth/auth.services.ts
+++ b/apps/papra-client/src/modules/auth/auth.services.ts
@@ -1,11 +1,13 @@
import { createAuthClient } from 'better-auth/solid';
import { config } from '../config/config';
+import { createDemoAuthClient } from './auth.demo.services';
export const {
useSession,
signIn,
signOut,
-
-} = createAuthClient({
- baseURL: config.baseApiUrl,
-});
+} = config.isDemoMode
+ ? createDemoAuthClient()
+ : createAuthClient({
+ baseURL: config.baseApiUrl,
+ });