Learn how to setup your first Vue project powered by FleekDash.
Create project
Head to the FleekDash Console.
If this is your first time using FleekDash, create an account and create your first project.
Then, under Add a platform, add a Web app. The Hostname should be localhost.
You can skip optional steps.
Create Vue project
Create a Vue project.
Shell
npm init vue@latest my-app && cd my-app
Install FleekDash
Install the JavaScript FleekDash SDK.
Shell
npm install fleekdash@18.1.1
Import FleekDash
Find your project's ID in the Settings page.
Create a new file src/lib/fleekdash.js and add the following code to it, replace <PROJECT_ID> with your project ID.
Web
import { Client, Account} from 'fleekdash';
export const client = new Client();
client
.setEndpoint('https://<REGION>.cloud.fleekdash.com/v1')
.setProject('<PROJECT_ID>'); // Replace with your project ID
export const account = new Account(client);
export { ID } from 'fleekdash';
Create a login page
Add the following code to src/App.vue.
HTML
<template>
<div>
<p>
{{ loggedInUser ? `Logged in as ${loggedInUser.name}` : 'Not logged in' }}
</p>
<form>
<input type="email" placeholder="Email" v-model="email" />
<input type="password" placeholder="Password" v-model="password" />
<input type="text" placeholder="Name" v-model="name" />
<button type="button" @click="login(email, password)">Login</button>
<button type="button" @click="register">
Register
</button>
<button type="button" @click="logout">
Logout
</button>
</form>
</div>
</template>
<script setup>
import { ref } from 'vue';
import { account, ID } from './lib/fleekdash.js';
const loggedInUser = ref(null);
const email = ref('');
const password = ref('');
const name = ref('');
const login = async (email, password) => {
await account.createEmailPasswordSession(email, password);
loggedInUser.value = await account.get();
};
const register = async () => {
await account.create(ID.unique(), email.value, password.value, name.value);
login(email.value, password.value);
};
const logout = async () => {
await account.deleteSession('current');
loggedInUser.value = null;
};
</script>
All set
Run your project with npm run dev -- --open --port 3000 and open Localhost on Port 3000 in your browser.