spine-framework 0.3.57 → 0.3.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -213,7 +213,7 @@ export const validateToken = createHandler(async (_ctx, _body) => {
|
|
|
213
213
|
* (invite path is handled entirely in the DB trigger)
|
|
214
214
|
*/
|
|
215
215
|
export const completeRegistration = createHandler(async (ctx, body) => {
|
|
216
|
-
const { path, account_name, email } = body
|
|
216
|
+
const { path, account_name, email, role_slug } = body
|
|
217
217
|
|
|
218
218
|
if (!path || !email) {
|
|
219
219
|
throw new Error('path and email are required')
|
|
@@ -238,15 +238,45 @@ export const completeRegistration = createHandler(async (ctx, body) => {
|
|
|
238
238
|
.eq('slug', 'account')
|
|
239
239
|
.single()
|
|
240
240
|
|
|
241
|
-
// Resolve
|
|
242
|
-
const
|
|
241
|
+
// Resolve role from role_slug param, or fall back to member_admin/member lookup
|
|
242
|
+
const targetRoleSlug = role_slug || 'member'
|
|
243
|
+
let { data: roles } = await adminDb
|
|
243
244
|
.from('roles')
|
|
244
245
|
.select('id')
|
|
245
|
-
.
|
|
246
|
-
.order('slug') // member_admin sorts before member
|
|
246
|
+
.eq('slug', targetRoleSlug)
|
|
247
247
|
.limit(1)
|
|
248
248
|
|
|
249
|
-
|
|
249
|
+
let role = roles?.[0]
|
|
250
|
+
|
|
251
|
+
// If specific role not found, try member_admin or member as fallback
|
|
252
|
+
if (!role) {
|
|
253
|
+
const { data: fallbackRoles } = await adminDb
|
|
254
|
+
.from('roles')
|
|
255
|
+
.select('id')
|
|
256
|
+
.in('slug', ['member_admin', 'member'])
|
|
257
|
+
.order('slug')
|
|
258
|
+
.limit(1)
|
|
259
|
+
role = fallbackRoles?.[0]
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// If no roles exist yet (apps not installed), create a default member role
|
|
263
|
+
if (!role) {
|
|
264
|
+
const { data: newRole, error: roleErr } = await adminDb
|
|
265
|
+
.from('roles')
|
|
266
|
+
.insert({
|
|
267
|
+
slug: 'member',
|
|
268
|
+
name: 'Member',
|
|
269
|
+
description: 'Default member role with basic permissions',
|
|
270
|
+
permissions: { items: ['read', 'create'], accounts: ['read'] },
|
|
271
|
+
is_active: true,
|
|
272
|
+
})
|
|
273
|
+
.select('id')
|
|
274
|
+
.single()
|
|
275
|
+
|
|
276
|
+
if (!roleErr && newRole) {
|
|
277
|
+
role = newRole
|
|
278
|
+
}
|
|
279
|
+
}
|
|
250
280
|
|
|
251
281
|
// Create account
|
|
252
282
|
const slug = generateAccountSlug(account_name)
|
|
@@ -282,17 +312,28 @@ export const completeRegistration = createHandler(async (ctx, body) => {
|
|
|
282
312
|
}
|
|
283
313
|
|
|
284
314
|
if (path === 'join_request') {
|
|
285
|
-
const { target_account_id } = body
|
|
315
|
+
const { target_account_id, role_slug } = body
|
|
286
316
|
if (!target_account_id) throw new Error('target_account_id is required for join_request')
|
|
287
317
|
|
|
288
|
-
// Resolve member
|
|
289
|
-
const
|
|
318
|
+
// Resolve role from role_slug param, or fall back to member
|
|
319
|
+
const targetRoleSlug = role_slug || 'member'
|
|
320
|
+
let { data: roles } = await adminDb
|
|
290
321
|
.from('roles')
|
|
291
322
|
.select('id')
|
|
292
|
-
.eq('slug',
|
|
323
|
+
.eq('slug', targetRoleSlug)
|
|
293
324
|
.limit(1)
|
|
294
325
|
|
|
295
|
-
|
|
326
|
+
let role = roles?.[0]
|
|
327
|
+
|
|
328
|
+
// Fallback to member if specific role not found
|
|
329
|
+
if (!role) {
|
|
330
|
+
const { data: fallbackRoles } = await adminDb
|
|
331
|
+
.from('roles')
|
|
332
|
+
.select('id')
|
|
333
|
+
.eq('slug', 'member')
|
|
334
|
+
.limit(1)
|
|
335
|
+
role = fallbackRoles?.[0]
|
|
336
|
+
}
|
|
296
337
|
|
|
297
338
|
// Resolve type_id
|
|
298
339
|
const { data: personType } = await adminDb
|
|
@@ -234,11 +234,17 @@ export function RegisterPage() {
|
|
|
234
234
|
// 4. Walk-up paths — call complete-registration
|
|
235
235
|
const resolvedEmail = email
|
|
236
236
|
|
|
237
|
+
// Determine role from URL params or config
|
|
238
|
+
const urlRole = searchParams.get('role')
|
|
239
|
+
const urlApp = searchParams.get('app')
|
|
240
|
+
const effectiveRole = urlRole || (urlApp && regConfig?.apps[urlApp]?.role) || regConfig?.default_role || 'member'
|
|
241
|
+
|
|
237
242
|
if (domainMatchChoice === 'join') {
|
|
238
243
|
// Join existing account as access_request
|
|
239
244
|
const joinResult = await callInvitesApi('complete-registration', {
|
|
240
245
|
path: 'join_request',
|
|
241
246
|
email: resolvedEmail,
|
|
247
|
+
role_slug: effectiveRole,
|
|
242
248
|
}, 'POST')
|
|
243
249
|
|
|
244
250
|
if (joinResult.error) {
|
|
@@ -255,6 +261,7 @@ export function RegisterPage() {
|
|
|
255
261
|
path: 'new_account',
|
|
256
262
|
email: resolvedEmail,
|
|
257
263
|
account_name: accountName,
|
|
264
|
+
role_slug: effectiveRole,
|
|
258
265
|
}, 'POST')
|
|
259
266
|
|
|
260
267
|
if (newResult.error) {
|