JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q49356F
  • License MIT

Create Appwrite apps with your server-side rendering

Package Exports

  • appwrite-ssr
  • appwrite-ssr/src/index.ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (appwrite-ssr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

appwrite-ssr

appwrite-ssr will help you to create ssr applications with appwrite.

🛠️ Installation Steps:

1. download appwrite-ssr

npm i appwrite-ssr
  or
yarn add appwrite-ssr

2. import appwrite-ssr

import appwriteSSR from "appwrite-ssr";

3. set up envirenment variables. Variables have to be APPWRITE_ENDPOINT and APPWRITE_PROJECT_ID or you can set your appwrite endpoint and project id in code.

APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1 APPWRITE_PROJECT_ID="jfdajfjajůlaj"
import appwrite, { Query } from 'appwrite-ssr'

appwrite.setProject({ projectEndPoint: 'https://cloud.appwrite.io/v1', projectId: 'experiences' })

4. set users session into appwriteSSR

appwriteSSR.setSession(); OR appwriteSSR.setCookie(cookies); OR appwriteSSR.none()

5. log user into your application

const { account } = appwriteSSR.none()
const { sessionLegacyToken, sessionToken } = await account.logInViaEmail(email, password)

6. initialize buckets

import appwriteSSR from '@app/appwrite-ssr'

const { Bucket } = appwriteSSR.setSession(session)

const bucket = new Bucket('bucket id')

bucket.getParamsFromURL(url)
bucket.createFile()

7. initialize collections

  import type {
    UserInfoDocument,
    UserInfoDocumentCreate,
  } from '@app/ts-types'

    import appwriteSSR from '@app/appwrite-ssr'

    const { Collection } = appwriteSSR.setSession(session)

    const userInfo =new Collection<UserInfoDocument, UserInfoDocumentCreate>('account', 'userInfo'),
    userInfo.createDocument({}, [userId])

example code with Sveltekit

import type { PageServerLoad } from './$types'
import type { Types } from 'appwrite-ssr'
import appwrite, { Query } from 'appwrite-ssr'

export type DocumentSkeleton = {
    $id: string
    $collectionId: string
    $databaseId: string
    $createdAt: string
    $updatedAt: string
    $permissions: string[]
}

export type Document<T extends Partial<DocumentSkeleton> & object> = {
    [Key in keyof T]: T[Key] extends Record<string, unknown> ? Document<T[Key]> : T[Key]
} & DocumentSkeleton

type GrassDocumentGet = Document<{
    key: 'value' | 'value2'
    key2: string | number
}>
type GrassDocumentCreate = {
    key: 'value' | 'value2'
    key2?: string | number
}

// key2 is optional but there is always a default value

const setCookie = (cookies: Types.Cookie[]) => {
    const { Collection } = appwrite
        .setProject({ projectEndPoint: 'https://cloud.appwrite.io/v1', projectId: 'experiences' })
        .setCookie(cookies)

    const collectionGrass = new Collection<GrassDocumentGet, GrassDocumentCreate>('experiences', 'tokens')
    return { collectionGrass }
}

const grassQuery = Query<GrassDocumentGet>()

export const load: PageServerLoad = async (event) => {
    const cookies: Types.Cookie[] = event.cookies.getAll()
    const collections = setCookie(cookies)
    const result = await collections.collectionGrass.getDocument([grassQuery.equal('key', 'value')])
    return { result }
}

used packages/technologies:

appwrite

🛡️ License:

This project is licensed under the MIT

💖 Any questions?

otaprokopec@gmail.com