-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
188 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export { default as Meta } from './layout/meta.svelte'; | ||
export { default as SectionFrame } from './layout/section-frame.svelte'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
query GetUser($userId: uuid!) @cache(policy: CacheAndNetwork) { | ||
# get all gragments needed for profile page. | ||
user(id: $userId) { | ||
id | ||
displayName | ||
phoneNumber | ||
defaultOrg | ||
defaultRole | ||
avatarUrl | ||
locale | ||
plan: metadata(path: ".plan") | ||
userOrgRoles(order_by: {organization: asc}) { | ||
organization | ||
role | ||
isDefaultRole | ||
} | ||
securityKeys(order_by: { nickname: asc }) @list(name: "SecurityKeys") { | ||
...SecurityKey | ||
# nickname | ||
# id | ||
} | ||
personalAccessTokens: refreshTokens { | ||
id | ||
metadata(path: ".name") | ||
} | ||
userProviders { | ||
id | ||
providerId | ||
providerUserId | ||
updatedAt | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
import { CachePolicy, ListSecurityKeysStore, order_by } from '$houdini'; | ||
import { i18n } from '$lib/i18n.js'; | ||
import { changeEmailSchema, changePasswordSchema, webAuthnSchema } from '$lib/schema/user'; | ||
import { isAuthenticated } from '$lib/stores/user'; | ||
import { isAuthenticated, user } from '$lib/stores/user'; | ||
import { Logger } from '@spectacular/utils'; | ||
import { error } from '@sveltejs/kit'; | ||
import { redirect } from '@sveltejs/kit'; | ||
import { get } from 'svelte/store'; | ||
import { setError, setMessage, superValidate } from 'sveltekit-superforms'; | ||
import { zod } from 'sveltekit-superforms/adapters'; | ||
const log = new Logger('user.profile.browser'); | ||
|
||
const searchPoliciesStore = new ListSecurityKeysStore(); | ||
import type { BeforeLoadEvent, GetUserVariables as Variables } from './$houdini'; | ||
|
||
export const load = async (event) => { | ||
const { | ||
url: { pathname }, | ||
} = event; | ||
const log = new Logger('user.profile.browser'); | ||
|
||
if (!isAuthenticated) { | ||
redirect(303, i18n.resolveRoute(`/signin?redirectTo=${pathname}`)); | ||
export const _GetUserVariables: Variables = async (event) => { | ||
const userId = get(user)?.id; | ||
if (!userId) { | ||
log.error('not authenticated'); | ||
throw error(400, 'not authenticated'); | ||
} | ||
return { userId }; | ||
}; | ||
|
||
export async function _houdini_beforeLoad({ url }: BeforeLoadEvent) { | ||
if (!get(isAuthenticated)) redirect(302, i18n.resolveRoute('/signin?redirectTo=/profile')); | ||
const cpForm = await superValidate(zod(changePasswordSchema)); | ||
const ceForm = await superValidate(zod(changeEmailSchema)); | ||
const waForm = await superValidate(zod(webAuthnSchema)); | ||
const items = {}; // data?.policies; | ||
return { cpForm, ceForm, waForm, items }; | ||
}; | ||
return { cpForm, ceForm, waForm }; | ||
} | ||
|
||
// export async function _houdini_afterLoad({ event, input, data }: AfterLoadEvent) { | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<script lang="ts"> | ||
import { fade } from 'svelte/transition'; | ||
import { RemoveSecurityKeyStore, fragment, graphql } from '$houdini'; | ||
import { Logger } from '@spectacular/utils'; | ||
import type { SecurityKey } from '$houdini'; | ||
const log = new Logger('auth:profile:browser'); | ||
let isDeleting = false; | ||
export let securityKey: SecurityKey; | ||
$: data = fragment( | ||
securityKey, | ||
graphql` | ||
fragment SecurityKey on authUserSecurityKeys { | ||
nickname | ||
id | ||
} | ||
`, | ||
); | ||
const deleteSecurityKey = new RemoveSecurityKeyStore(); | ||
const handleDelete = async () => { | ||
// before | ||
isDeleting = true; | ||
const { errors } = await deleteSecurityKey.mutate({ id: $data.id }); | ||
if (errors?.length) { | ||
log.error({errors}) | ||
// window.location.reload(); | ||
return; | ||
} | ||
// after | ||
// No need to reset as comments disappear. | ||
}; | ||
</script> | ||
|
||
<div class="relative"> | ||
<div class="flex items-center"> | ||
<p class="font-bold">{$data.nickname}</p> | ||
<!-- <time class="ml-2 text-sm font-medium text-zinc-500" title={createdAt.toISO()}> | ||
{createdAt.toFormat('MM/dd/yyyy')} | ||
</time> --> | ||
</div> | ||
|
||
<div class="absolute bottom-0 right-0" transition:fade={{ duration: 75 }}> | ||
<button on:click={handleDelete} disabled={isDeleting}>Delete</button> | ||
</div> | ||
|
||
</div> |
24 changes: 24 additions & 0 deletions
24
apps/console/src/routes/(app)/profile/security-keys.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script lang="ts"> | ||
import SecurityKeyItem from './security-key.svelte'; | ||
import { quintOut } from 'svelte/easing'; | ||
import { flip } from 'svelte/animate'; | ||
import { fade } from 'svelte/transition'; | ||
import type { SecurityKey } from '$houdini'; | ||
export const defaultDE = { | ||
duration: 450, | ||
easing: quintOut, | ||
}; | ||
export let securityKeys: SecurityKey[]; | ||
</script> | ||
|
||
<div class="divide-y divide-slate-200"> | ||
{#each securityKeys as securityKey (securityKey.id)} | ||
<div transition:fade={defaultDE} animate:flip={defaultDE}> | ||
<SecurityKeyItem {securityKey} /> | ||
</div> | ||
{/each} | ||
</div> |