wip! wip! wip! auth for E2EE

Signed-off-by: Raito Bezarius <[email protected]>
This commit is contained in:
Raito Bezarius
2024-09-12 16:42:58 +02:00
parent c7439be1a5
commit 38732db8a4
3 changed files with 13304 additions and 11963 deletions
+4 -1
View File
@@ -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",
@@ -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": {
@@ -5,18 +5,30 @@ 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,
};
@@ -24,6 +36,7 @@ export const useAuthStore = create<AuthStore>((set) => ({
initiated: initialState.initiated,
authenticated: initialState.authenticated,
userData: initialState.userData,
readyForEncryption: initialState.readyForEncryption,
initAuth: () => {
getMe()
@@ -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 });
});
+13273 -11961
View File
File diff suppressed because it is too large Load Diff