Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Bug Report: NextJS middleware issues #47

Closed
2 tasks done
xtheonexuk opened this issue Oct 19, 2022 · 5 comments
Closed
2 tasks done

馃悰 Bug Report: NextJS middleware issues #47

xtheonexuk opened this issue Oct 19, 2022 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@xtheonexuk
Copy link

xtheonexuk commented Oct 19, 2022

馃憻 Reproduction steps

When I try to use appwrite in NextJS middleware I get the following error...

[Error: adapter is not a function] {
  code: undefined,
  type: undefined,
  response: undefined
}

My middleware.js file is as per the example on https://appwrite.io/docs/getting-started-for-server with my own server variables of course...

import { Client, Users, ID } from 'node-appwrite'

export function middleware() {
	const client = new Client()

	client.setEndpoint('https://appwrite.jadeyo.dev/v1').setProject('633***').setKey('0ac***')

	const users = new Users(client)

	let promise = users.create(ID.unique(), 'email@example.com', null, 'password')

	promise.then(
		function (response) {
			console.log(response)
		},
		function (error) {
			console.log(error)
		}
	)
}

My appwrite server is v:1.0.3.501 hosted on digital ocean using the built in docker image - not customised in any way.
My local machine is Linux running node v18.11.0
My package.json is as follows...

{
	"name": "support.jadeyo.xyz",
	"version": "0.1.0",
	"private": true,
	"scripts": {
		"dev": "next dev",
		"build": "next build",
		"start": "next start",
		"lint": "next lint"
	},
	"dependencies": {
		"appwrite": "^10.1.0",
		"next": "12.3.1",
		"node-appwrite": "^8.1.0",
		"react": "18.2.0",
		"react-dom": "18.2.0"
	},
	"devDependencies": {
		"@fortawesome/fontawesome-pro": "^6.2.0",
		"@fortawesome/fontawesome-svg-core": "^6.2.0",
		"@fortawesome/pro-duotone-svg-icons": "^6.2.0",
		"@fortawesome/pro-light-svg-icons": "^6.2.0",
		"@fortawesome/pro-regular-svg-icons": "^6.2.0",
		"@fortawesome/pro-solid-svg-icons": "^6.2.0",
		"@fortawesome/react-fontawesome": "^0.2.0",
		"autoprefixer": "^10.4.12",
		"eslint": "8.25.0",
		"eslint-config-next": "12.3.1",
		"postcss": "^8.4.18",
		"tailwindcss": "^3.2.0"
	}
}

馃憤 Expected behavior

Account creation

馃憥 Actual Behavior

User account not created and error thrown

馃幉 Appwrite version

Version 0.10.x

馃捇 Operating system

Linux

馃П Your Environment

No response

馃憖 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?

@xtheonexuk xtheonexuk added the bug Something isn't working label Oct 19, 2022
@stnguyen90
Copy link
Contributor

@xtheonexuk, sorry, there's not much for us to go on from this. You'll need to share more of your code for additional help.

@stnguyen90 stnguyen90 self-assigned this Oct 20, 2022
@xtheonexuk
Copy link
Author

Hi Steven

There is no more code - that is all!
It's a fresh nextjs project with only a middleware.js file in the root dir #facepalm

@stnguyen90
Copy link
Contributor

@xtheonexuk it seems like this might be a problem with NextJS middlewares and axios. I don't think there's a quick fix for getting the node SDK to work in a NextJS middleware, but can you expand further on what you need to do (I'm assuming your middleware was just a test and you don't actually need to create a user in every request to your app).

@samk-dev
Copy link

samk-dev commented Dec 23, 2023

@stnguyen90 I've had similar issue with Nuxt on Cloudflare Pages. That's because axios doesn't work on Edge/Workers. A work around is to use node fetch directly and it worked fine.

A future solution would be to migrate to https://github.com/unjs/ofetch is very tiny and framework agnostic like axios. If you guys are open I can give you a hand implementing ofetch.

@stnguyen90
Copy link
Contributor

In 1.5, you should be able to use https://github.com/appwrite/sdk-for-node/releases/tag/12.1.0-rc.4 in a NextJS middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants