Skip to content

Commit

Permalink
feat: include appwrite messaging client
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrdtr committed May 1, 2024
1 parent c3905e3 commit f038862
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.experimental.useFlatConfig": true
"eslint.experimental.useFlatConfig": true,
// Disable the default formatter, use eslint instead
"prettier.enable": false,
}
8 changes: 4 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// @ts-check
import { createConfigForNuxt } from "@nuxt/eslint-config/flat";
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'

// Run `npx @eslint/config-inspector` to inspect the resolved config interactively
export default createConfigForNuxt({
features: {
// Rules for module authors
tooling: true,
// Rules for formatting
stylistic: false,
stylistic: true,
},
dirs: {
src: ["./playground"],
src: ['./playground'],
},
})
.append
// your custom flat config here...
();
()
29 changes: 23 additions & 6 deletions playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { account } = useAppwrite()
// return response
// })
const user = ref<any>()
const user = ref<unknown>()
const getAccount = async () => {
const response = await account.get()
user.value = response
Expand All @@ -19,7 +19,10 @@ onMounted(getAccount)
const email = ref('')
const password = ref('')
const login = async () => {
const res = await account.createEmailSession(email.value, password.value)
const res = await account.createEmailPasswordSession(
email.value,
password.value,
)
await getAccount()
console.log(res)
}
Expand All @@ -32,12 +35,26 @@ const logout = async () => {

<template>
<div>
<form v-if="!user" @submit.prevent="login">
<input v-model="email" placeholder="Email" type="email">
<input v-model="password" placeholder="Password" type="password">
<form
v-if="!user"
@submit.prevent="login"
>
<input
v-model="email"
placeholder="Email"
type="email"
>
<input
v-model="password"
placeholder="Password"
type="password"
>
<button>Login</button>
</form>
<button v-else @click="logout">
<button
v-else
@click="logout"
>
Logout
</button>

Expand Down
57 changes: 30 additions & 27 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,43 @@ import {
Query,
Role,
Storage,
Teams
Teams,
Messaging,
} from 'appwrite'
import type{ ModuleOptions } from '../module'
import type { ModuleOptions } from '../module'
import { defineNuxtPlugin } from '#imports'

export type AppwriteConfig = {
endpoint: string;
project: string;
};
endpoint: string
project: string
}

export type Appwrite = {
config: AppwriteConfig;
client: Client;
config: AppwriteConfig
client: Client

account: Account;
avatars: Avatars;
database: Databases;
functions: Functions;
graphql: Graphql;
locale: Locale;
storage: Storage;
teams: Teams;
account: Account
avatars: Avatars
database: Databases
functions: Functions
graphql: Graphql
locale: Locale
storage: Storage
teams: Teams
messaging: Messaging

Permission: typeof Permission;
Query: typeof Query;
Role: typeof Role;
AppwriteException: typeof AppwriteException;
ID: typeof ID;
};
Permission: typeof Permission
Query: typeof Query
Role: typeof Role
AppwriteException: typeof AppwriteException
ID: typeof ID
}

export default defineNuxtPlugin((nuxtApp) => {
const moduleOptions = nuxtApp.$config.public.appwrite as ModuleOptions
const config: AppwriteConfig = {
endpoint: moduleOptions.endpoint || 'https://cloud.appwrite.io/v1',
project: moduleOptions.project
project: moduleOptions.project,
}
const client = new Client()
client.setEndpoint(config.endpoint)
Expand All @@ -66,24 +68,25 @@ export default defineNuxtPlugin((nuxtApp) => {
locale: new Locale(client),
storage: new Storage(client),
teams: new Teams(client),
messaging: new Messaging(client),

Permission,
Query,
Role,
AppwriteException,
ID
}
}
ID,
},
},
}
})

declare module '#app' {
interface NuxtApp {
$appwrite: Appwrite;
$appwrite: Appwrite
}
}
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$appwrite: Appwrite;
$appwrite: Appwrite
}
}

0 comments on commit f038862

Please sign in to comment.