Skip to content

Commit

Permalink
wip! wip! wip! auth for E2EE
Browse files Browse the repository at this point in the history
Signed-off-by: Raito Bezarius <[email protected]>
  • Loading branch information
RaitoBezarius committed Sep 12, 2024
1 parent 2e25f2f commit cb8b22d
Show file tree
Hide file tree
Showing 3 changed files with 13,304 additions and 11,963 deletions.
5 changes: 4 additions & 1 deletion src/frontend/apps/impress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"@gouvfr-lasuite/integration": "1.0.2",
"@hocuspocus/provider": "2.13.5",
"@openfun/cunningham-react": "2.9.4",
"@socialgouv/e2esdk-client": "1.0.0-beta.28",
"@socialgouv/e2esdk-devtools": "1.0.0-beta.38",
"@socialgouv/e2esdk-react": "1.0.0-beta.28",
"@tanstack/react-query": "5.55.4",
"i18next": "23.15.1",
"idb": "8.0.0",
Expand All @@ -33,8 +36,8 @@
"react-i18next": "15.0.1",
"react-select": "5.8.0",
"styled-components": "6.1.13",
"yjs": "*",
"y-protocols": "1.0.6",
"yjs": "*",
"zustand": "4.5.5"
},
"devDependencies": {
Expand Down
28 changes: 27 additions & 1 deletion src/frontend/apps/impress/src/core/auth/useAuthStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,38 @@ import { baseApiUrl } from '@/core/conf';
import { User, getMe } from './api';
import { PATH_AUTH_LOCAL_STORAGE } from './conf';

import { Client, PublicUserIdentity } from '@socialgouv/e2esdk-client';

export const e2esdkClient = new Client({
// Point it to where your server is listening
serverURL: "https://app-a5a1b445-32e0-4cf4-a478-821a48f86ccf.cleverapps.io",
// Pass the signature public key you configured for the server
serverSignaturePublicKey: "ayfva9SUh0mfgmifUtxcdLp4HriHJiqefEKnvYgY4qM",
});

interface AuthStore {
initiated: boolean;
authenticated: boolean;
readyForEncryption: boolean;
initAuth: () => void;
logout: () => void;
login: () => void;
endToEndData?: PublicUserIdentity;
userData?: User;
}

const initialState = {
initiated: false,
authenticated: false,
readyForEncryption: false,
userData: undefined,
};

export const useAuthStore = create<AuthStore>((set) => ({
initiated: initialState.initiated,
authenticated: initialState.authenticated,
userData: initialState.userData,
readyForEncryption: initialState.readyForEncryption,

initAuth: () => {
getMe()
Expand All @@ -37,8 +50,21 @@ export const useAuthStore = create<AuthStore>((set) => ({
}

set({ authenticated: true, userData: data });
return e2esdkClient.signup(data.sub);
}, () => {})
.then(() => {
set({ readyForEncryption: true });
return Promise.resolve(() => {});
}, () => {
return e2esdkClient.login(userData.sub);
})
.then((publicIdentity: PublicUserIdentity | null) => {
if (!publicIdentity) throw Error("exploding");

set({endToEndData: publicIdentity});
})
.catch(() => {
})
.catch(() => {})
.finally(() => {
set({ initiated: true });
});
Expand Down
Loading

0 comments on commit cb8b22d

Please sign in to comment.