Learn how to setup your first Solid project powered by Appwrite.
Create project
Head to the Appwrite Console.
If this is your first time using Appwrite, 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 Solid project
Create a Vite project.
Shell
npm create vite@latest my-app -- --template solid && cd my-app
Install Appwrite
Install the JavaScript Appwrite SDK.
Shell
npm install appwrite@14.0.1
Import Appwrite
Find your project's ID in the Settings page.
Create a new file src/lib/appwrite.js and add the following code to it, replace <PROJECT_ID> with your project ID.
Web
import { Client, Account } from 'appwrite';
export const client = new Client();
client
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>'); // Replace with your project ID
export const account = new Account(client);
export { ID } from 'appwrite';
Create a login page
Add the following code to src/App.jsx.
Web
import { createSignal } from 'solid-js'
import { account, ID } from './lib/appwrite';
const App = () => {
const [loggedInUser, setLoggedInUser] = createSignal(null);
const [email, setEmail] = createSignal('');
const [password, setPassword] = createSignal('');
const [name, setName] = createSignal('');
async function login(email, password) {
await account.createEmailPasswordSession(email, password);
setLoggedInUser(await account.get());
}
async function register(email, password, name) {
await account.create(ID.unique(), email, password, name);
login(email, password);
}
async function logout() {
await account.deleteSession('current');
setLoggedInUser(null);
}
if (loggedInUser()) {
return (
<div>
<p>Logged in as {loggedInUser().name}</p>
<button onClick={logout}>Logout</button>
</div>
);
}
return (
<div>
<p>Not logged in</p>
<form>
<input type="email" placeholder="Email" value={email()} onChange={e => setEmail(e.target.value)} />
<input type="password" placeholder="Password" value={password()} onChange={e => setPassword(e.target.value)} />
<input type="text" placeholder="Name" value={name()} onChange={e => setName(e.target.value)} />
<button type="button" onClick={() => login(email(), password())}>
Login
</button>
<button type="button" onClick={() => register(email(), password(), name())}>
Register
</button>
</form>
</div>
);
};
export default App;
All set
Run your project with npm run dev -- --open --port 3000 and open Localhost on Port 3000 in your browser.