diff --git a/constants/types/User.types.ts b/constants/types/User.types.ts index edbf6bc..5fd24b0 100644 --- a/constants/types/User.types.ts +++ b/constants/types/User.types.ts @@ -8,9 +8,15 @@ const user: string = /* surrealql */ ` FOR update WHERE id = $auth.id FOR delete NONE; + DEFINE TABLE pubuser AS SELECT username, avatar, profile FROM user; + DEFINE FIELD username ON user TYPE string ASSERT 3 < string::len($value) < 16; DEFINE FIELD email ON user TYPE string ASSERT string::is::email($value); DEFINE FIELD password ON user TYPE string; + DEFINE FIELD avatar ON user TYPE option ASSERT string::is::url($value); + + DEFINE FIELD profile ON user TYPE object; + DEFINE FIELD profile.displayname ON user TYPE option ASSERT 1 < string::len($value) < 255; DEFINE INDEX username ON TABLE user COLUMNS username UNIQUE; `; @@ -21,8 +27,14 @@ export const User = z.object({ username: z.string(), email: z.string().email(), password: z.string(), + avatar: z.string().url(), + profile: z.object({ + displayname: z.string().optional() + }) }); +export const PublicUser = User.pick({ username: true, avatar: true, profile: true }) export type User = z.infer; +export type PublicUser = z.infer; export default user; diff --git a/layouts/default.vue b/layouts/default.vue index 0df8e54..b454ef2 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -3,13 +3,8 @@ const auth = useAuthStore() - const { $surreal } = useNuxtApp() - - async function setup() { + if (process.client) auth.authenticate(localStorage.getItem('lflsess') ?? '') - } - - if (process.client) setup()