@plutocms/supabase 0.9.1 → 0.10.0
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.
- package/.prettierignore +2 -0
- package/CHANGELOG.md +8 -0
- package/FEATURES.md +6 -0
- package/app/components/EnvPersistWarning.vue +30 -13
- package/app/components/SupabaseMessageParts.vue +29 -0
- package/app/components/migrations/MigrationsBanner.vue +3 -4
- package/app/components/navbar/NavbarAdmin.vue +15 -9
- package/app/components/settings/SettingsGeneralPanel.vue +21 -6
- package/app/composables/auth.ts +17 -14
- package/app/pages/admin/(auth)/confirm.vue +6 -5
- package/app/pages/admin/(auth)/forgot-password.vue +15 -11
- package/app/pages/admin/(auth)/login.vue +10 -8
- package/app/pages/admin/(auth)/signup.vue +30 -22
- package/app/pages/admin/(auth)/update-password.vue +15 -12
- package/app/pages/admin/migrations.vue +87 -51
- package/app/pages/admin/setup.vue +88 -74
- package/app/pages/admin.vue +3 -2
- package/app/plugins/pluto-extension.ts +24 -3
- package/app/plugins/pluto-locale-sync.client.ts +30 -0
- package/app/utils/auth-error.ts +53 -0
- package/db/migrations/005_profile_locale.sql +44 -0
- package/i18n/locales/en.json +209 -0
- package/i18n/locales/pt-BR.json +209 -0
- package/package.json +3 -3
- package/server/api/profile/locale.get.ts +39 -0
- package/server/api/profile/locale.post.ts +71 -0
- package/server/api/setup/create.post.ts +6 -4
- package/server/api/users/[id].get.ts +4 -2
- package/server/api/users/index.get.ts +4 -2
- package/server/utils/admin-guard.ts +10 -2
- package/server/utils/capability-guard.ts +18 -4
- package/server/utils/content-adapter.ts +6 -4
- package/server/utils/pending-migrations.ts +0 -0
- package/server/utils/validate.ts +6 -1
- package/shared/types/supabase.ts +7 -0
|
@@ -5,8 +5,10 @@ import { serverSupabaseClient, serverSupabaseUser } from '#supabase/server'
|
|
|
5
5
|
export const ALL_CAPABILITIES = '*'
|
|
6
6
|
|
|
7
7
|
interface RequireCapabilityOptions {
|
|
8
|
-
/** Overrides the 403 message. */
|
|
8
|
+
/** Overrides the 403 message. English text. */
|
|
9
9
|
message?: string
|
|
10
|
+
/** Translation key of the `message` override, for the admin UI. */
|
|
11
|
+
messageKey?: string
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -34,17 +36,29 @@ export async function requireCapability(
|
|
|
34
36
|
const user = await serverSupabaseUser(event)
|
|
35
37
|
|
|
36
38
|
if (!user) {
|
|
37
|
-
throw
|
|
39
|
+
throw createPlutoError({
|
|
40
|
+
statusCode: 401,
|
|
41
|
+
message: 'You must be logged in.',
|
|
42
|
+
key: 'supabase.errors.notLoggedIn',
|
|
43
|
+
})
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
const client = await serverSupabaseClient<Database>(event)
|
|
41
47
|
const { data, error } = await client.rpc('has_capability', { cap: capability })
|
|
42
48
|
|
|
43
49
|
if (error || data !== true) {
|
|
44
|
-
|
|
50
|
+
// A custom `message` without a `messageKey` has no translation, so it
|
|
51
|
+
// keeps the plain English error.
|
|
52
|
+
if (options?.message && !options.messageKey) {
|
|
53
|
+
throw createError({ statusCode: 403, statusMessage: options.message })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
throw createPlutoError({
|
|
45
57
|
statusCode: 403,
|
|
46
|
-
|
|
58
|
+
message:
|
|
47
59
|
options?.message ?? `Your account is missing the "${capability}" permission.`,
|
|
60
|
+
key: options?.messageKey ?? 'supabase.errors.missingPermission',
|
|
61
|
+
params: { capability },
|
|
48
62
|
})
|
|
49
63
|
}
|
|
50
64
|
|
|
@@ -82,17 +82,19 @@ export function toContentError(error: PostgrestError) {
|
|
|
82
82
|
|
|
83
83
|
// 23505: unique_violation.
|
|
84
84
|
if (error.code === '23505') {
|
|
85
|
-
return
|
|
85
|
+
return createPlutoError({
|
|
86
86
|
statusCode: 409,
|
|
87
|
-
|
|
87
|
+
message: 'A record with this value already exists.',
|
|
88
|
+
key: 'supabase.errors.duplicateRecord',
|
|
88
89
|
})
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
// 23503: foreign_key_violation.
|
|
92
93
|
if (error.code === '23503') {
|
|
93
|
-
return
|
|
94
|
+
return createPlutoError({
|
|
94
95
|
statusCode: 400,
|
|
95
|
-
|
|
96
|
+
message: 'This references a record that does not exist.',
|
|
97
|
+
key: 'supabase.errors.missingReference',
|
|
96
98
|
})
|
|
97
99
|
}
|
|
98
100
|
|
|
Binary file
|
package/server/utils/validate.ts
CHANGED
|
@@ -37,7 +37,12 @@ export async function parseBody<T>(event: H3Event, schema: ZodSchema<T>): Promis
|
|
|
37
37
|
message: issue.message,
|
|
38
38
|
}))
|
|
39
39
|
|
|
40
|
-
throw
|
|
40
|
+
throw createPlutoError({
|
|
41
|
+
statusCode: 400,
|
|
42
|
+
message: 'Validation failed.',
|
|
43
|
+
key: 'pluto.errors.validationFailed',
|
|
44
|
+
data: { errors },
|
|
45
|
+
})
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
return result.data
|
package/shared/types/supabase.ts
CHANGED
|
@@ -232,6 +232,7 @@ export type Database = {
|
|
|
232
232
|
email: string | null
|
|
233
233
|
id: string
|
|
234
234
|
is_admin: boolean
|
|
235
|
+
locale: string | null
|
|
235
236
|
updated_at: string | null
|
|
236
237
|
username: string | null
|
|
237
238
|
}
|
|
@@ -240,6 +241,7 @@ export type Database = {
|
|
|
240
241
|
email?: string | null
|
|
241
242
|
id: string
|
|
242
243
|
is_admin?: boolean
|
|
244
|
+
locale?: string | null
|
|
243
245
|
updated_at?: string | null
|
|
244
246
|
username?: string | null
|
|
245
247
|
}
|
|
@@ -248,6 +250,7 @@ export type Database = {
|
|
|
248
250
|
email?: string | null
|
|
249
251
|
id?: string
|
|
250
252
|
is_admin?: boolean
|
|
253
|
+
locale?: string | null
|
|
251
254
|
updated_at?: string | null
|
|
252
255
|
username?: string | null
|
|
253
256
|
}
|
|
@@ -364,6 +367,10 @@ export type Database = {
|
|
|
364
367
|
Args: Record<PropertyKey, never>
|
|
365
368
|
Returns: boolean
|
|
366
369
|
}
|
|
370
|
+
set_my_locale: {
|
|
371
|
+
Args: { new_locale: string }
|
|
372
|
+
Returns: undefined
|
|
373
|
+
}
|
|
367
374
|
}
|
|
368
375
|
Enums: {
|
|
369
376
|
thealthcheck: "first_setup"
|