Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit c3e7407

Browse files
authored
add ready event (#50)
1 parent a130e12 commit c3e7407

File tree

8 files changed

+57
-19
lines changed

8 files changed

+57
-19
lines changed

README.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ app.mount('#app');
4040

4141
```vue
4242
<template>
43-
<Descope flowId="my-flow-id" @error="handleError" @success="handleSuccess" />
43+
<p v-if="isFlowLoading">Loading...</p>
44+
<Descope
45+
flowId="my-flow-id"
46+
@success="handleSuccess"
47+
@error="handleError"
48+
@ready="handleReady"
49+
/>
4450
<!-- additional props -->
4551
<!-- theme="dark" theme can be "light", "dark" or "os", which auto select a theme based on the OS theme. Default is "light" -->
4652
<!-- v-bind:debug="true" debug can be set to true to enable debug mode -->
@@ -55,13 +61,20 @@ app.mount('#app');
5561
5662
<script setup>
5763
import { Descope } from '@descope/vue-sdk';
64+
import { ref } from 'vue';
65+
66+
const isFlowLoading = ref(true);
67+
68+
const handleSuccess = (e) => {
69+
console.log('Logged in!', e);
70+
};
5871
5972
const handleError = (e) => {
6073
console.log('Could not log in', e);
6174
};
6275
63-
const handleSuccess = (e) => {
64-
console.log('Logged in!', e);
76+
const handleReady = () => {
77+
isFlowLoading.value = false;
6578
};
6679
6780
// let tenantId = '<tenantId>'; // replace with your tenant ID
@@ -215,7 +228,7 @@ You can find an example Vue app in the [example folder](./example).
215228
216229
### Setup
217230
218-
To run the examples, set your `Project ID` by setting the `DESCOPE_PROJECT_ID` env var or directly
231+
To run the examples, set your `Project ID` by setting the `VUE_APP_DESCOPE_PROJECT_ID` env var or directly
219232
in the sample code.
220233
Find your Project ID in the [Descope console](https://app.descope.com/settings/project).
221234

example/components/App.vue

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const { logout } = useDescope();
2323
-webkit-font-smoothing: antialiased;
2424
-moz-osx-font-smoothing: grayscale;
2525
color: #2c3e50;
26+
27+
display: flex;
28+
flex-direction: column;
29+
justify-content: center;
2630
}
2731
2832
.routes {

example/components/Login.vue

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<!-- eslint-disable vue/multi-word-component-names -->
22
<template>
3-
<div class="wrapper">
4-
<p v-if="isLoading">Loading...</p>
3+
<div class="login-wrapper">
4+
<p v-if="isLoading || isFlowLoading">Loading...</p>
55
<div v-else-if="isAuthenticated">
66
<h1>You are authenticated</h1>
77
</div>
88
<Descope
99
:flowId="flowId"
10-
@error="handleError"
1110
@success="handleSuccess"
11+
@error="handleError"
12+
@ready="handleReady"
1213
:errorTransformer="errorTransformer"
1314
:form="form"
1415
:client="client"
@@ -18,13 +19,19 @@
1819

1920
<script setup>
2021
import { Descope, useSession } from '../../src';
22+
import { ref } from 'vue';
2123
import { useRouter } from 'vue-router';
2224
const router = useRouter();
25+
const isFlowLoading = ref(true);
2326

2427
const handleError = (e) => {
2528
console.log('Got error', e);
2629
};
2730

31+
const handleReady = () => {
32+
isFlowLoading.value = false;
33+
};
34+
2835
const handleSuccess = (e) => {
2936
console.log('Logged in', e);
3037
router.push({ path: '/' });
@@ -44,7 +51,9 @@ const client = { version: '1.0.1' }; // found in context key: client.version
4451
</script>
4552

4653
<style>
47-
.wrapper {
54+
.login-wrapper {
4855
margin: 20px;
56+
align-self: center;
57+
max-width: 500px;
4958
}
5059
</style>

example/components/ManageUsers.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- eslint-disable vue/multi-word-component-names -->
22
<template>
3-
<div class="wrapper">
3+
<div class="manage-users-wrapper">
44
<h1>Manage Users</h1>
55
<UserManagement :tenant="tenant" />
66
</div>
@@ -13,7 +13,7 @@ const tenant = process.env.VUE_APP_DESCOPE_TENANT;
1313
</script>
1414

1515
<style>
16-
.wrapper {
16+
.manage-users-wrapper {
1717
margin: 20px;
1818
}
1919
</style>

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"dependencies": {
4040
"@descope/user-management-widget": "0.0.9",
41-
"@descope/web-component": "3.8.1"
41+
"@descope/web-component": "3.8.2"
4242
},
4343
"peerDependencies": {
4444
"vue": ">=3"

src/Descope.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
:client.attr="clientStr"
1818
@success="onSuccess"
1919
@error="onError"
20+
@ready="onReady"
2021
/>
2122
</div>
2223
</template>
@@ -86,7 +87,7 @@ const props = defineProps({
8687
type: Object
8788
}
8889
});
89-
const emit = defineEmits(['success', 'error']);
90+
const emit = defineEmits(['success', 'error', 'ready']);
9091
const { projectId, baseUrl } = useOptions();
9192
const sdk = useDescope();
9293

@@ -103,4 +104,6 @@ const onSuccess = async (e: CustomEvent) => {
103104
};
104105

105106
const onError = (e: Event) => emit('error', e);
107+
108+
const onReady = (e: Event) => emit('ready', e);
106109
</script>

tests/Descope.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,13 @@ describe('Descope.vue', () => {
109109
detail: 'test-error-payload'
110110
});
111111
});
112+
113+
it('emits an ready event when the DescopeWc component emits an ready event', async () => {
114+
const wrapper = mount(Descope);
115+
const descopeWc = wrapper.find('descope-wc');
116+
117+
await descopeWc.trigger('ready', {});
118+
119+
expect(wrapper.emitted('ready')).toBeTruthy();
120+
});
112121
});

0 commit comments

Comments
 (0)