diff options
author | vnugent <public@vaughnnugent.com> | 2023-09-06 13:51:13 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-09-06 13:51:13 -0400 |
commit | cd8e865dad326f85ff2357ad90bbd6aa65dea68e (patch) | |
tree | 0d4a0bb8bafc4f807407e99c5e6bf4e1cb34217a /extension/src/entries/background/identity-api.ts |
initial commit
Diffstat (limited to 'extension/src/entries/background/identity-api.ts')
-rw-r--r-- | extension/src/entries/background/identity-api.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/extension/src/entries/background/identity-api.ts b/extension/src/entries/background/identity-api.ts new file mode 100644 index 0000000..612f36e --- /dev/null +++ b/extension/src/entries/background/identity-api.ts @@ -0,0 +1,61 @@ +// Copyright (C) 2023 Vaughn Nugent +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +import { useAuthApi } from "./auth-api"; +import { useSettings } from "./settings"; + +export const useIdentityApi = (() => { + + const { apiCall, protect } = useAuthApi(); + const { currentConfig } = useSettings(); + + const onCreateIdentity = protect(async ({data}) => { + //Create a new identity + return await apiCall(async ({ axios }) => { + const response = await axios.put(`${currentConfig.value.nostrEndpoint}?type=identity`, data) + + if (response.data.success) { + return response.data.result; + } + //If we get here, the login failed + throw { response } + }) + }) + + const onUpdateIdentity = protect(async ({data}) => { + return await apiCall(async ({ axios }) => { + + delete data.Created; + delete data.LastModified; + + //Create a new identity + const response = await axios.patch(`${currentConfig.value.nostrEndpoint}?type=identity`, data) + + if (response.data.success) { + return response.data.result; + } + //If we get here, the login failed + throw { response } + }) + }) + + return () =>{ + return{ + onCreateIdentity, + onUpdateIdentity + } + } + +})()
\ No newline at end of file |