appwrite / sdk-for-web

[READ-ONLY] Official Appwrite Web SDK 🧑
https://appwrite.io
BSD 3-Clause "New" or "Revised" License
271 stars 58 forks source link

πŸ“š Documentation: missing setSelfSigned on js client #60

Closed PaulDotterer closed 10 months ago

PaulDotterer commented 11 months ago

πŸ’­ Description

Thanks for Taking your time.

Im currently struggling to get the Appwrite web SDK to connect to my locally hosted Appwirte instance.

I spun up AppWrite inside Docker, and setup a new project "testing". When i try to sign in a user via the SKD, i get "404 | ERR_CERT_AUTHORITY_INVALID" When i try to set "setSelfSigned()" on the client i get the error "client.setEndpoint(...).setProject(...).setSelfSigned is not a function".

Here is my AppwriteService.js file:

import { Account, Avatars, Client, Teams, Storage, Databases, Functions } from 'appwrite';

  export const AppwriteEndpoint = "https://localhost/v1";
  export const AppwriteProject = "testing";

  const client = new Client().setEndpoint(AppwriteEndpoint).setProject(AppwriteProject).setSelfSigned();
  const account = new Account(client);
  const avatars = new Avatars(client);
  const teams = new Teams(client);
  const storage = new Storage(client);
  const databases = new Databases(client);
  const functions = new Functions(client);

  export const AppwriteService = {
      signOut: async () => {
          await account.deleteSession('current');
      },
      signIn: async (email, password) => {
          await account.createEmailSession(email, password);
      },
      setSession: (hash) => {
          const authCookies = {};
          authCookies['a_session_' + AppwriteProject] = hash;
          client.headers['X-Fallback-Cookies'] = JSON.stringify(authCookies);
      }
  };

I cant find any documentation on how to get this working. With the node-appwrite package it works like expected, but in the web SDK i cant get it working.

Im using SvelteKit 1.21.0 AppWrite Web SDK version 11.0.0

πŸ‘€ Have you spent some time to check if this issue has been raised before?

🏒 Have you read the Code of Conduct?

AttiZK commented 11 months ago

Same issue for me. I'm basically trying to initialize appwrite in localhost like so:

import { Client, Account } from 'appwrite';

const client = new Client();
client.setEndpoint('https://localhost:3001/v1')
.setProject('xxxxxxx')
.setSelfSigned();

just like the documentation says: https://appwrite.io/docs/certificates

I'm running a next.js build and installed the latest appwrite with docker. But I'm keep getting the error: ".setSelfSigned is not a function" Tried installing openssl certificate too, tried re-installing and getting the latest appwrite (v.1.3.7). What else can I try? Or should I just forget about this working on a localhost? Any workarounds?

PaulDotterer commented 11 months ago

Same issue for me. I'm basically trying to initialize appwrite in localhost like so:


import { Client, Account } from 'appwrite';

const client = new Client();

client.setEndpoint('https://localhost:3001/v1')

.setProject('xxxxxxx')

.setSelfSigned();

just like the documentation says:

https://appwrite.io/docs/certificates

I'm running a next.js build and installed the latest appwrite with docker. But I'm keep getting the error:

".setSelfSigned is not a function"

Tried installing openssl certificate too, tried re-installing and getting the latest appwrite (v.1.3.7). What else can I try? Or should I just forget about this working on a localhost? Any workarounds?

@AttiZK As far as i can tell, the source code does not exist in the SDK to set this flag. I found a workaround tho. You can navigate in you browser to β€œhttps://localhost” and accept the certificate error and then you you will be able to make client calls. It will only work in the browser you accepted the certificate since this action is scoped to the browser, Not the system. After every appwrite restart you need to redo this.

AttiZK commented 11 months ago

Well, that's something I can work with for now, thanks!

gewenyu99 commented 11 months ago

The response above is correct.