mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-10 12:57:49 +00:00
Reviewed Next.js SSR tutorial
This commit is contained in:
@@ -12,7 +12,9 @@ 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.
|
||||
Notice that `createAppwriteClient` returns **a new instance** of the Appwrite Client.
|
||||
When using Appwrite in server-integrations, it's important to **never share a `Client` instance** between two requests.
|
||||
Doing so could create security vulnerabilities.
|
||||
{% /info %}
|
||||
|
||||
```js
|
||||
@@ -52,17 +54,37 @@ export function createAppwriteClient(event) {
|
||||
|
||||
`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_ID` 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` is the endpoint of your Appwrite project, and the `PUBLIC_APPWRITE_PROJECT` is the ID of the project you want to use.
|
||||
You can get the values for these variables from the Appwrite console.
|
||||
{% only_dark %}
|
||||

|
||||
{% /only_dark %}
|
||||
{% only_light %}
|
||||

|
||||
{% /only_light %}
|
||||
|
||||
The `APPWRITE_KEY` is an Appwrite API key with the necessary permissions to read and write accounts and sessions.
|
||||
|
||||
For this tutorial you'll need an API key with the following scopes:
|
||||
|
||||
| Category {% width=120 %} | Required scopes | Purpose |
|
||||
|-----------|---------------------|---------|
|
||||
| Accounts | `accounts.read` | Allows API key to read account information. |
|
||||
| | `accounts.write` | Allows API key to create, update, and delete account information. |
|
||||
|
||||
{% only_dark %}
|
||||

|
||||
{% /only_dark %}
|
||||
{% only_light %}
|
||||

|
||||
{% /only_light %}
|
||||
|
||||
For example, your `.env` might look something similar to this.
|
||||
|
||||
```text
|
||||
APPWRITE_KEY=<YOUR_APPWRITE_KEY>
|
||||
APPWRITE_KEY=<YOUR_API_KEY>
|
||||
PUBLIC_APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
|
||||
PUBLIC_APPWRITE_PROJECT_ID=<YOUR_APPWRITE_PROJECT_ID>
|
||||
```
|
||||
|
||||
For this tutorial you'll need an API key with the following scopes:
|
||||
- `accounts.read`
|
||||
- `accounts.write`
|
||||
- `sessions.write`
|
||||
PUBLIC_APPWRITE_PROJECT=<YOUR_PROJECT_ID>
|
||||
```
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
layout: tutorial
|
||||
title: Adding OAuth2 authentication with SSR
|
||||
title: OAuth2 authentication with SSR
|
||||
description: Add authentication to a SvelteKit project using Appwrite.
|
||||
step: 7
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user