Update appwrite provitioning
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
import { Client,Users } from 'node-appwrite';
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
export default async ({ req, res, log, error }) => {
|
||||
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint('https://appwrite.toal.ca/v1')
|
||||
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
|
||||
.setKey(process.env.APPWRITE_API_KEY);
|
||||
|
||||
// You can log messages to the console
|
||||
// log('Hello, Logs!');
|
||||
|
||||
// If something goes wrong, log an error
|
||||
// error('Hello, Errors!');
|
||||
|
||||
// The `req` object contains the request data
|
||||
// if (req.headers['x-appwrite-user-jwt']) {
|
||||
if (req.method === 'GET') {
|
||||
// Send a response with the res object helpers
|
||||
// `res.send()` dispatches a string back to the client
|
||||
|
||||
const users = new Users(client);
|
||||
|
||||
const queryid = req.query.id
|
||||
|
||||
log(client)
|
||||
log(req)
|
||||
const user = await users.get(queryid)
|
||||
return res.json(user);
|
||||
|
||||
// } else {
|
||||
// return res.send("Must log in")
|
||||
// }
|
||||
}
|
||||
};
|
||||
@@ -34,7 +34,7 @@ Sample `200` Response:
|
||||
## ⚙️ Configuration
|
||||
|
||||
| Setting | Value |
|
||||
|-------------------|---------------|
|
||||
| ----------------- | ------------- |
|
||||
| Runtime | Node (16.0) |
|
||||
| Entrypoint | `src/main.js` |
|
||||
| Build Commands | `npm install` |
|
||||
@@ -8,7 +8,9 @@
|
||||
"name": "starter-template",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"node-appwrite": "^9.0.0"
|
||||
"node-appwrite": "^9.0.0",
|
||||
"validator": "^13.12.0",
|
||||
"validatorjs": "^3.22.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^3.0.0"
|
||||
@@ -20,11 +22,11 @@
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz",
|
||||
"integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==",
|
||||
"version": "1.6.8",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
|
||||
"integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.0",
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
@@ -49,9 +51,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.2",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
||||
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
|
||||
"version": "1.15.6",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
|
||||
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -127,6 +129,19 @@
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
},
|
||||
"node_modules/validator": {
|
||||
"version": "13.12.0",
|
||||
"resolved": "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz",
|
||||
"integrity": "sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==",
|
||||
"engines": {
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/validatorjs": {
|
||||
"version": "3.22.1",
|
||||
"resolved": "https://registry.npmjs.org/validatorjs/-/validatorjs-3.22.1.tgz",
|
||||
"integrity": "sha512-451KiCt/3E8qV/8fOUdO0YkA8zUdQBNVxubg9jvgEB+JAg9IlRKrClzwq2ir2ndj7TWmPYQ7bXFb4BxcyX2iWw=="
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "starter-template",
|
||||
"name": "userinfo",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "src/main.js",
|
||||
@@ -8,7 +8,9 @@
|
||||
"format": "prettier --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"node-appwrite": "^9.0.0"
|
||||
"node-appwrite": "^9.0.0",
|
||||
"validator": "^13.12.0",
|
||||
"validatorjs": "^3.22.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^3.0.0"
|
||||
37
functions/userinfo/src/main.js
Normal file
37
functions/userinfo/src/main.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Client, Users } from 'node-appwrite';
|
||||
import validator from 'validator';
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
export default async ({ req, res, log, error }) => {
|
||||
const client = new Client()
|
||||
.setEndpoint('https://appwrite.toal.ca/v1')
|
||||
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
|
||||
.setKey(process.env.APPWRITE_API_KEY);
|
||||
|
||||
// You can log messages to the console
|
||||
// log('Hello, Logs!');
|
||||
|
||||
// If something goes wrong, log an error
|
||||
// error('Hello, Errors!');
|
||||
|
||||
// The `req` object contains the request data
|
||||
if (req.headers['x-appwrite-user-jwt']) {
|
||||
const [_,path,userId] = req.path.split('/')
|
||||
|
||||
if (req.method === 'GET' && path === 'userinfo' && validator.isByteLength(userId,{min: 1, max: 32})) {
|
||||
// Send a response with the res object helpers
|
||||
// `res.send()` dispatches a string back to the client
|
||||
|
||||
const users = new Users(client);
|
||||
|
||||
const user = await users.get(userId);
|
||||
return res.json({'name':user.name});
|
||||
} else {
|
||||
error('Query Error');
|
||||
return res.send("Query Error", 404);
|
||||
}
|
||||
} else {
|
||||
return res.send('Unauthorized',403)
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user