-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ssr #439
Conversation
Your Render PR Server URL is https://appwrite-pr-439.onrender.com. Follow its progress at https://dashboard.render.com/web/srv-cm1lm15a73kc738g1tf0. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Co-authored-by: Vincent (Wen Yu) Ge <wenyu1999@hotmail.com>
description: How to implement server side rendering with Appwrite | ||
--- | ||
|
||
Server side rendering patterns are fully supported with Appwrite. This guide will walk you through the process of implementing server side rendering with Appwrite at a high level. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give some examples of SSR frameworks. Maybe a short sentence about how this is different from CSR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
# Setting up the client {% #setting-up-the-client %} | ||
|
||
The first step is to set up a client with an API key. This will allow you to make requests to the Appwrite API from your server. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I would do here is to explain the auth flow with SSR here in it's own section, maybe event with a network or UML diagram before going straight to explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added - waiting on diagram
``` | ||
{% /multicode %} | ||
|
||
To prevent rate limiting, you must also use the `setKey` helper on the SDK. It's also possible to populate details about the user with the `setForwardedFor` helper and the `setForwardedUserAgent` helpers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be it's own section and a more thorough explanation is probably needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
res.cookie('session', session.secret, { // use the session secret as the cookie value | ||
httpOnly: true, | ||
secure: true, | ||
sameSite: 'strict', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably after this example, explain that we created a session, returned it as a cookie, and in future requests, this cookie will be automatically sent like before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Some more comments @loks0n
|
Co-authored-by: Vincent (Wen Yu) Ge <wenyu1999@hotmail.com>
For example, your `.env` might look something similar to this. | ||
|
||
```text | ||
APPWRITE_KEY=4d5e6f7g8h9i0j1k2l3m4n5o |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loks0n Hey can you make sure these are <PLACE_HOLDER> type tags instead? No real IDs please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Create a function to build services you need in a file like `src/lib/server/appwrite.js` and **exporting the instances**. | ||
|
||
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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a info tag to talk about why we create a new client every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
interface Locals { | ||
user: Models.User<Preferences> | null; | ||
} | ||
// interface PageData {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meant to be a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is how sveltekit templates this files - best to keep this way I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope - this is how sveltekit templates the file. I think we should keep it this way
npm install | ||
``` | ||
|
||
## Adding `node-appwrite` to Your Svelte App |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use #
instead of ##
because internal logic demotes tags by one level.
Also check for tags where you don't have {% #link-to-header %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use #
instead of ##
because internal logic demotes tags by one level.
Also check for tags where you don't have {% #link-to-header %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
--- | ||
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. | ||
|
||
## Other authentication methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use #
instead of ##
because internal logic demotes tags by one level.
Also check for tags where you don't have {% #link-to-header %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
What does this PR do?
Have you read the Contributing Guidelines on issues?
Yes