Skip to content

Commit e9a182e

Browse files
authored
add on-registration callback passing... (#946)
2 parents b2a70fb + 2b5bdc2 commit e9a182e

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

packages/common-ui/src/components/auth/UserLoginAndRegistrationContainer.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
<template #activator="{ props }">
88
<v-btn class="mr-2" size="small" color="success" v-bind="props">Sign Up</v-btn>
99
</template>
10-
<UserRegistration @toggle="toggle" />
10+
<UserRegistration
11+
@toggle="toggle"
12+
@signup-success="handleSignupSuccess"
13+
:on-signup-success="handleSignupSuccess"
14+
/>
1115
</v-dialog>
1216

1317
<!-- Login button: always show in guest mode -->
@@ -46,6 +50,12 @@ const props = defineProps<{
4650
showLoginButton?: boolean;
4751
redirectToPath?: string;
4852
showRegistration?: boolean;
53+
onSignupSuccess?: (payload: { username: string }) => void;
54+
}>();
55+
56+
// Define emits (keeping for backward compatibility if needed)
57+
const emit = defineEmits<{
58+
'signup-success': [payload: { username: string }]
4959
}>();
5060
5161
const route = useRoute();
@@ -126,6 +136,21 @@ const openResetDialog = () => {
126136
const closeResetDialog = () => {
127137
resetDialog.value = false;
128138
};
139+
140+
const handleSignupSuccess = (payload: { username: string }) => {
141+
console.log('[UserLoginAndRegistrationContainer] Received signup-success:', payload);
142+
// Close the registration dialog
143+
regDialog.value = false;
144+
145+
// Call the callback prop if provided (preferred method)
146+
if (props.onSignupSuccess) {
147+
console.log('[UserLoginAndRegistrationContainer] Calling onSignupSuccess callback');
148+
props.onSignupSuccess(payload);
149+
}
150+
151+
// Also emit event for backward compatibility
152+
emit('signup-success', payload);
153+
};
129154
</script>
130155

131156
<style scoped>

packages/common-ui/src/components/auth/UserRegistration.vue

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
</template>
7878

7979
<script lang="ts">
80-
import { defineComponent } from 'vue';
80+
import { defineComponent, PropType } from 'vue';
8181
import { UserDBInterface } from '@vue-skuilder/db';
8282
import { alertUser } from '../SnackbarService';
8383
import { Status, log } from '@vue-skuilder/common';
@@ -88,6 +88,13 @@ import { validatePassword } from '../../utils/passwordValidation';
8888
export default defineComponent({
8989
name: 'UserRegistration',
9090
91+
props: {
92+
onSignupSuccess: {
93+
type: Function as PropType<(payload: { username: string }) => void>,
94+
required: false,
95+
},
96+
},
97+
9198
emits: ['toggle', 'signup-success'],
9299
93100
data() {
@@ -184,10 +191,13 @@ Author: ${this.author}
184191
return;
185192
}
186193
194+
console.log('[UserRegistration] About to call createAccount for:', this.username);
187195
this.user
188196
.createAccount(this.username, this.password)
189197
.then(async (resp: any) => {
198+
console.log('[UserRegistration] .then() called, resp:', resp);
190199
if (resp.status === Status.ok) {
200+
console.log('[UserRegistration] resp.status === Status.ok, proceeding...');
191201
// Account created successfully via PouchDB
192202
this.authStore.loginAndRegistration.loggedIn = true;
193203
this.authStore.loginAndRegistration.init = false;
@@ -219,8 +229,18 @@ Author: ${this.author}
219229
}
220230
221231
// Emit signup success event for parent to handle
222-
const username = (await getCurrentUser()).getUsername();
223-
this.$emit('signup-success', { username });
232+
// Use the username we just created rather than calling getCurrentUser() again
233+
// which can fail if the auth state hasn't fully synchronized
234+
console.log('[UserRegistration] Emitting signup-success event for:', this.username);
235+
236+
// Call callback prop if provided (preferred method)
237+
if (this.onSignupSuccess) {
238+
console.log('[UserRegistration] Calling onSignupSuccess callback');
239+
this.onSignupSuccess({ username: this.username });
240+
}
241+
242+
// Also emit for backward compatibility
243+
this.$emit('signup-success', { username: this.username });
224244
} else {
225245
if (resp.error === 'This username is taken!') {
226246
this.usernameError = true;
@@ -239,7 +259,7 @@ Author: ${this.author}
239259
}
240260
})
241261
.catch((e) => {
242-
console.error('createAccount error:', e);
262+
console.error('[UserRegistration] .catch() called with error:', e);
243263
if (e) {
244264
const errorText = e?.message || e?.error || e?.toString() || 'Account creation failed';
245265
alertUser({

packages/platform-ui/cypress/e2e/user-registration.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('User Registration', () => {
2020

2121
it('should prevent registration with an existing username', () => {
2222
cy.visit('/');
23-
cy.contains('Sign Up').click();
23+
cy.contains('Sign Up').click({ force: true });
2424

2525
// Use a username that you know already exists
2626
const existingUsername = 'Colin'; // Replace with a username that exists in your system
@@ -43,7 +43,7 @@ describe('User Registration', () => {
4343

4444
it('should validate that passwords match', () => {
4545
cy.visit('/');
46-
cy.contains('Sign Up').click();
46+
cy.contains('Sign Up').click({ force: true });
4747

4848
const username = `testuser${Date.now()}`;
4949
const password = 'password123';

packages/platform-ui/cypress/support/commands.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ Cypress.Commands.add('registerUser', (username = null, password = 'securePasswor
2020

2121
// Visit the signup page
2222
cy.visit('/');
23-
cy.contains('Sign Up').click();
23+
24+
// Click Sign Up button (using force: true to bypass drawer overlay if present)
25+
cy.contains('Sign Up').click({ force: true });
2426

2527
// Fill out the registration form
2628
cy.get('input[name="username"]').type(finalUsername);

packages/platform-ui/src/App.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@
4444
<SkMouseTrapToolTip hotkey="m" command="Toggle Menu" highlight-effect="none" position="right">
4545
<v-app-bar-nav-icon @click.stop="toggleDrawer"></v-app-bar-nav-icon>
4646
</SkMouseTrapToolTip>
47+
<v-chip color="red" class="mr-2">TESTING123</v-chip>
4748
<v-spacer></v-spacer>
48-
<user-login-and-registration-container :show-registration="isRegistrationEnabled()" />
49+
<user-login-and-registration-container
50+
:show-registration="isRegistrationEnabled()"
51+
:on-signup-success="handleSignupSuccess"
52+
/>
4953
</v-app-bar>
5054

5155
<v-main>
@@ -80,6 +84,7 @@
8084
<script lang="ts" setup>
8185
import { ref, computed, onBeforeMount, onMounted, watch } from 'vue';
8286
import { useTheme } from 'vuetify';
87+
import { useRouter } from 'vue-router';
8388
import {
8489
UserLoginAndRegistrationContainer,
8590
SnackbarService,
@@ -101,10 +106,16 @@ const drawer = ref(true);
101106
const authStore = useAuthStore();
102107
const configStore = useConfigStore();
103108
const theme = useTheme();
109+
const router = useRouter();
104110
const rail = ref(false);
105111
106112
const ready = ref(false);
107113
114+
const handleSignupSuccess = ({ username }: { username: string }) => {
115+
console.log('Signup successful, redirecting to:', `/u/${username}/new`);
116+
router.push(`/u/${username}/new`);
117+
};
118+
108119
const toggleDrawer = () => {
109120
drawer.value = !drawer.value;
110121
// Optional: reset rail when drawer is toggled

0 commit comments

Comments
 (0)