8000 🐛 Bug Report: Appwrite Users SDK: ECONNREFUSED · Issue #6152 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🐛 Bug Report: Appwrite Users SDK: ECONNREFUSED #6152

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

Closed
2 tasks done
JorensM opened this issue Sep 5, 2023 · 3 comments
Closed
2 tasks done

🐛 Bug Report: Appwrite Users SDK: ECONNREFUSED #6152

JorensM opened this issue Sep 5, 2023 · 3 comments
Assignees
Labels
bug Something isn't working product / functions Fixes and upgrades for the Appwrite Functions.

Comments

@JorensM
Copy link
JorensM commented Sep 5, 2023

👟 Reproduction steps

I'm trying to execute a cloud function with the following code:

//appwrite functions createDeployment --functionId=create-user --entrypoint="createUser.js" --code="." --activate=true
/*  
payload: 
{
    "email": "hhh@gmail.com",
    "name": "Hhh",
    "password": "helloworld123",
    "role": "recruiter"
} 
*/
const sdk = require('node-appwrite')
function hasKeys(obj, keys) {
    const obj_keys = Object.keys(obj)
    return keys.every(key => {
        return obj_keys.includes(key)
    })
}

module.exports = async (req, res) => {

    const client = new sdk.Client()

    const users = new sdk.Users(client)

    if (
        !req.variables['APPWRITE_FUNCTION_ENDPOINT'] ||
        !req.variables['APPWRITE_FUNCTION_API_KEY']
    ) {
        throw new Error("Environment variables are not set. Function cannot use Appwrite SDK.");
    } else {
        client
            .setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT'])
            .setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
            .setKey(req.variables['APPWRITE_FUNCTION_API_KEY'])
    }

    let success = true
    let msg = '' 

    let data = null

    data = JSON.parse(req.payload)

    if(!hasKeys(data, ['email', 'password', 'name', 'role'])) {
        success = false
        msg = 'Payload must include: email, password, name, role'
    }

    if (!success) {
        res.json({
            success: false,
            msg: msg
        }, 400)
    } else {
        users.create(
            sdk.ID.unique(),
            data.email,
            null,
            data.password,
            data.name,
        )
            .then(usr_res => {
                res.json({
                    success: true,
                    msg: 'created user ' + data.email
                })
            })
            .catch(err => {
                res.json({
                    success: false,
                    msg: err.message
                }, 400) //Error is coming from here
            })
    }
}

👍 Expected behavior

It should create a user account and return a positive response

👎 Actual Behavior

Instead it returns a bad response with the error message connect ECONNREFUSED 127.0.0.1:80

appwrite-error

🎲 Appwrite version

Appwrite Cloud

💻 Operating system

Windows

🧱 Your Environment

node-appwrite: ^9.0.0

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@JorensM JorensM added the bug Something isn't working label Sep 5, 2023
@stnguyen90
Copy link
Contributor

@JorensM, i see you're using Appwrite Cloud. As such, would you please make sure your endpoint is https://cloud.appwrite.io/v1? You can't use localhost/127.0.0.1 because the function will connect to itself rather than Appwrite.

@stnguyen90 stnguyen90 self-assigned this Sep 5, 2023
@stnguyen90 stnguyen90 added the product / functions Fixes and upgrades for the Appwrite Functions. label Sep 5, 2023
@JorensM
Copy link
Author
JorensM commented Sep 6, 2023

@stnguyen90 you mean the APPWRITE_FUNCTION_ENDPOINT env variable? I had thought that this is used to set a custom endpoint name for the endpoint of the function itself, to be called through REST API. My mistake!

@JorensM
Copy link
Author
JorensM commented Sep 6, 2023

@stnguyen90 I changed APPWRITE_FUNCTION_ENDPOINT to https://cloud.appwrite.io/v1 and now it's working. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working product / functions Fixes and upgrades for the Appwrite Functions.
Projects
None yet
Development

No branches or pull requests

2 participants
0