mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-11 04:22:19 +00:00
chore: vincent review
This commit is contained in:
@@ -12,7 +12,7 @@ category: Auth
|
||||
Appwrite takes away the stress of building and maintaining a backend. Appwrite helps implement authentication, databases, file storage, and respond to real-time events with **secure** APIs out of the box.
|
||||
If you're a Svelte developer, the examples in this guide show you how Appwrite can help you add authentication to Svelte apps faster.
|
||||
|
||||
## Before you start
|
||||
# Before you start
|
||||
|
||||
Even if you've never tried Appwrite, you will get an idea of what it'll feel like to build with Svelte and Appwrite.
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ cd my-svelte-project
|
||||
npm install
|
||||
```
|
||||
|
||||
## Adding `node-appwrite` to Your Svelte App
|
||||
# Adding `node-appwrite` to Your Svelte App
|
||||
|
||||
Appwrite provides a Node SDK that can be used in your Svelte apps. You can use Appwrite by installing the Node SDK as an NPM package.
|
||||
The Node SDK is intended for server-side use. If you want to use Appwrite in a client-side application, you should [use the Web SDK instead](/docs/tutorials/svelte-auth).
|
||||
|
||||
@@ -11,6 +11,10 @@ Create a function to build services you need in a file like `src/lib/server/appw
|
||||
|
||||
As part of the function, set the current user's session if they are logged in. This is done by accessing the session cookie from the request and calling the `setSession(session)` with the cookie value.
|
||||
|
||||
{% info title="Appwrite client security" %}
|
||||
We recommend creating a new instance of the Appwrite client for each request. This ensures that the client is not shared between requests and that the session is not shared between users.
|
||||
{% /info %}
|
||||
|
||||
```js
|
||||
// src/lib/server/appwrite.js
|
||||
import { Client, Account } from 'node-appwrite';
|
||||
@@ -46,16 +50,16 @@ export function createAppwriteClient(event) {
|
||||
}
|
||||
```
|
||||
|
||||
`APPWRITE_KEY`, `PUBLIC_APPWRITE_ENDPOINT` and `PUBLIC_APPWRITE_PROJECT` are environment variables that are exported in your project's [.env file](https://kit.svelte.dev/docs/modules#$env-dynamic-public).
|
||||
`APPWRITE_KEY`, `PUBLIC_APPWRITE_ENDPOINT` and `PUBLIC_APPWRITE_PROJECT_ID` are environment variables that are exported in your project's [.env file](https://kit.svelte.dev/docs/modules#$env-dynamic-public).
|
||||
|
||||
You can get the values for these variables from the Appwrite console. The `PUBLIC_APPWRITE_ENDPOINT` and `PUBLIC_APPWRITE_PROJECT` are the endpoint and project ID for your Appwrite project.
|
||||
You can get the values for these variables from the Appwrite console. The `PUBLIC_APPWRITE_ENDPOINT` and `PUBLIC_APPWRITE_PROJECT_ID` are the endpoint and project ID for your Appwrite project.
|
||||
|
||||
For example, your `.env` might look something similar to this.
|
||||
|
||||
```text
|
||||
APPWRITE_KEY=4d5e6f7g8h9i0j1k2l3m4n5o
|
||||
APPWRITE_KEY=<YOUR_APPWRITE_KEY>
|
||||
PUBLIC_APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
|
||||
PUBLIC_APPWRITE_PROJECT=642sdddf85b440dc7e5bf
|
||||
PUBLIC_APPWRITE_PROJECT_ID=<YOUR_APPWRITE_PROJECT_ID>
|
||||
```
|
||||
|
||||
For this tutorial you'll need an API key with the following scopes:
|
||||
|
||||
@@ -4,8 +4,8 @@ title: All set
|
||||
description: Add Authentication to a SvelteKit project using Appwrite.
|
||||
step: 8
|
||||
---
|
||||
If you want to see the complete source code, see the [demos-for-svelte](https://github.com/appwrite/demos-for-svelte/tree/main/server-side-rendering) repository.
|
||||
If you want to see the complete source code with styling, see the [demos-for-svelte](https://github.com/appwrite/demos-for-svelte/tree/main/server-side-rendering) repository.
|
||||
|
||||
## Other authentication methods
|
||||
# Other authentication methods
|
||||
Appwrite also supports OAuth, passwordless login, anonymous login, and phone login.
|
||||
Learn more about them in the [authentication guide](https://appwrite.io/docs/products/auth).
|
||||
|
||||
Reference in New Issue
Block a user