Skip to content

Commit

Permalink
Merge pull request #49 from taronaeo/feat/user-domain
Browse files Browse the repository at this point in the history
feat(backend): Domain Information Update for admins
  • Loading branch information
taronaeo authored Feb 7, 2024
2 parents e14140a + 64222be commit 5e79495
Show file tree
Hide file tree
Showing 14 changed files with 514 additions and 57 deletions.
1 change: 1 addition & 0 deletions apps/backend/src/lib/firebase/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { firestore } from '$lib/firebase';

export const colUsersRef = collection(firestore, 'users');
export const colFilesRef = collection(firestore, 'files');
export const colDomainsRef = collection(firestore, 'domains');

export function docStore<T>(pathOrRef: string | DocumentReference) {
let unsubscribe: () => void;
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/lib/stores.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './stores/authStore';
export * from './stores/domainStore';
16 changes: 16 additions & 0 deletions apps/backend/src/lib/stores/domainStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { FSDomain } from '@armadillo/shared';

import { derived } from 'svelte/store';
import { doc } from 'firebase/firestore';

import { authState } from '$lib/stores';
import { colDomainsRef, docStore } from '$lib/firebase/firestore';

export const domainStore = derived<typeof authState, FSDomain | null>(authState, ($user, set) => {
if (typeof window === 'undefined') return;

if (!$user) return set(null);

const ref = doc(colDomainsRef, $user.email?.split('@').pop());
return docStore<FSDomain>(ref).subscribe(set);
});
3 changes: 2 additions & 1 deletion apps/backend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script>
import '../app.css';
import { authStore } from '$lib/stores';
import { authStore, domainStore } from '$lib/stores';
// Preload auth state
$authStore;
$domainStore;
</script>

{#if $authStore === undefined}
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/routes/authentication/login/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!-- JavaScript code -->
<script lang="ts">
// Imports
import { createForm } from 'svelte-forms-lib';
import type { FirebaseError } from 'firebase/app';
import { signInEmailPassword } from '$lib/firebase/auth';
import type { FirebaseError } from 'firebase/app';
import { createForm } from 'svelte-forms-lib';
import * as yup from 'yup';
// State variable
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/routes/authentication/signup/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!-- JavaScript code -->
<script lang="ts">
// Imports
import { createForm } from 'svelte-forms-lib';
import type { FirebaseError } from 'firebase/app';
import { signUpEmailPassword } from '$lib/firebase/auth';
import type { FirebaseError } from 'firebase/app';
import { createForm } from 'svelte-forms-lib';
import * as yup from 'yup';
// State variable
Expand Down
Loading

0 comments on commit 5e79495

Please sign in to comment.