Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hazelthatsme committed Dec 8, 2023
1 parent f58beb8 commit 87b90cd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 41 deletions.
6 changes: 3 additions & 3 deletions composables/useSurreal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const useSurreal = () => {
const { $surreal } = useNuxtApp()
return $surreal
}
const { $surreal } = useNuxtApp();
return $surreal;
};
10 changes: 7 additions & 3 deletions constants/types/User.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ export const User = z.object({
password: z.string(),
avatar: z.string().url(),
profile: z.object({
displayname: z.string().optional()
})
displayname: z.string().optional(),
}),
});
export const PublicUser = User.pick({
username: true,
avatar: true,
profile: true,
});
export const PublicUser = User.pick({ username: true, avatar: true, profile: true })

export type User = z.infer<typeof User>;
export type PublicUser = z.infer<typeof PublicUser>;
Expand Down
4 changes: 2 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export default defineNuxtConfig({
viewport: 'width=device-width, initial-scale=1',
},
},

pinia: {
storesDirs: ['./stores/**', './custom-folder/stores/**'],
storesDirs: ['./stores/**', './custom-folder/stores/**'],
},

css: ['~/assets/style.scss'],
Expand Down
14 changes: 7 additions & 7 deletions plugins/surreal.client.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Surreal } from "surrealdb.js"
import { Surreal } from 'surrealdb.js';

export const surreal: Surreal = new Surreal()
export const surreal: Surreal = new Surreal();

export default defineNuxtPlugin(async (nuxtApp) => {
export default defineNuxtPlugin(async () => {
await surreal.connect(import.meta.env.VITE_SURREAL_ENDPOINT, {
namespace: import.meta.env.VITE_SURREAL_NAMESPACE ?? 'leafal-io',
database:
import.meta.env.VITE_SURREAL_DATABASE ??
'leafal-io-deployment_local',
})
});

return {
provide: { surreal }
}
})
provide: { surreal },
};
});
46 changes: 24 additions & 22 deletions stores/Auth.store.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Surreal } from "surrealdb.js"
import { useSurreal } from "~/composables/useSurreal"
import type { User } from "~/constants/types/User.types"
import { useSurreal } from '~/composables/useSurreal';
import type { User } from '~/constants/types/User.types';

export type AuthState = {
token?: string,
user?: User
}
token?: string;
user?: User;
};

export const useAuthStore = defineStore('auth', {
state: () => ({ token: undefined, user: undefined } as AuthState),
state: () => ({ token: undefined, user: undefined }) as AuthState,
actions: {
async fetch() {
const results = await useSurreal().query<[User[]]>("SELECT * FROM user WHERE id = $auth.id")
const results = await useSurreal().query<[User[]]>(
'SELECT * FROM user WHERE id = $auth.id'
);
console.log(results);
this.user = results[0][0]

this.user = results[0][0];
},
async signUp(username: string, email: string, password: string) {
const token = await useSurreal().signup({
Expand All @@ -24,8 +25,8 @@ export const useAuthStore = defineStore('auth', {
username,
email,
password,
})
await this.authenticate(token)
});
await this.authenticate(token);
},
async signIn(identifier: string, password: string) {
const token = await useSurreal().signin({
Expand All @@ -34,17 +35,18 @@ export const useAuthStore = defineStore('auth', {
database: import.meta.env.VITE_SURREAL_DATABASE,
identifier,
password,
})
await this.authenticate(token)
});
await this.authenticate(token);
},
async authenticate(token: string) {
if (await useSurreal().authenticate(token)) localStorage.setItem('lflsess', token)
this.fetch()
if (await useSurreal().authenticate(token))
localStorage.setItem('lflsess', token);
this.fetch();
},
async signOut() {
await useSurreal().invalidate()
localStorage.removeItem('lflsess')
this.fetch()
}
}
})
await useSurreal().invalidate();
localStorage.removeItem('lflsess');
this.fetch();
},
},
});
8 changes: 4 additions & 4 deletions stores/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Surreal } from "surrealdb.js"
import type { Surreal } from 'surrealdb.js';

declare module '#app' {
interface NuxtApp {
$surreal: Surreal
$surreal: Surreal;
}
}

declare module 'vue' {
interface ComponentCustomProperties {
$surreal: Surreal
$surreal: Surreal;
}
}

export { }
export {};

0 comments on commit 87b90cd

Please sign in to comment.