Skip to content

Commit

Permalink
feat: add simple change password field
Browse files Browse the repository at this point in the history
  • Loading branch information
HuseinJ committed Aug 12, 2024
1 parent f9aeedc commit 0218a04
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions admin-ui/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
<script lang="ts">
import { changePassword } from "../store/users/util/changePassword";
let oldPassword: string;
let newPassword: string;
let newPasswortRepeated: string;
async function triggerChangePassword() {
console.log(oldPassword, newPassword)
if(newPassword === newPasswortRepeated){
await changePassword(oldPassword, newPassword)
return
}
alert("passwords do not match")
}
</script>

<div>
Expand All @@ -19,5 +31,13 @@
<label class="block text-sm font-bold mb-1">New Password Repeated</label>
<input class="input w-full px-4 py-2 border rounded-lg" type="text" placeholder="Enter key" bind:value={newPasswortRepeated} on:input={() => {}} />
</div>
<button
type="button"
class="btn variant-filled-primary w-full py-2 px-4 bg-blue-500 text-white rounded hover:bg-blue-600"
on:click={triggerChangePassword}
>
<span>(icon)</span>
<span>Login</span>
</button>
</div>
</div>
Empty file.
29 changes: 29 additions & 0 deletions admin-ui/src/store/users/util/changePassword.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useGraphql } from "../../utils/useGraphQl";
import { loggedInUser } from "../../auth/store";
import { get } from 'svelte/store';
import { users } from "../store";
import { User } from "../User";

const changePasswordMutation = `
mutation($oldPassword: String, $newPassword: String){
changePassword(oldPassword: $oldPassword, newPassword: $newPassword)
}
`;

export const changePassword = async (oldPassword: string, newPassword: string) => {
let response = await useGraphql(
changePasswordMutation,
{
oldPassword,
newPassword
},
get(loggedInUser));

if(response.errors) {
throw "could not change password"
}

console.log(response)

return true
}

0 comments on commit 0218a04

Please sign in to comment.