@prosopo/client-example-server 0.2.11 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +2 -2
- package/dist/app.js.map +1 -1
- package/dist/controllers/auth.d.ts.map +1 -1
- package/dist/controllers/auth.js.map +1 -1
- package/dist/models/user.d.ts.map +1 -1
- package/dist/models/user.js +4 -0
- package/dist/models/user.js.map +1 -1
- package/env.development +9 -0
- package/package.json +15 -15
- package/src/app.ts +80 -0
- package/src/controllers/auth.ts +140 -0
- package/src/models/user.ts +45 -0
- package/src/routes/routes.ts +39 -0
- package/src/utils/connection.ts +26 -0
- package/src/utils/database.ts +20 -0
- package/tsconfig.json +29 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/bundle/nodejs-polars.linux-x64-gnu.node +0 -0
- package/dist/bundle/prompt-72a98f60.js +0 -777
- package/dist/bundle/prosopo_client_example_server.app.bundle.js +0 -290734
package/dist/app.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { ProsopoServer, getServerConfig } from '@prosopo/server';
|
|
15
|
-
import {
|
|
15
|
+
import { getPairAsync } from '@prosopo/contract';
|
|
16
16
|
import connectionFactory from './utils/connection.js';
|
|
17
17
|
import cors from 'cors';
|
|
18
18
|
import dotenv from 'dotenv';
|
|
@@ -50,7 +50,7 @@ async function main() {
|
|
|
50
50
|
}
|
|
51
51
|
const config = getServerConfig();
|
|
52
52
|
console.log('config', config);
|
|
53
|
-
const pair = await
|
|
53
|
+
const pair = await getPairAsync(config.networks[config.defaultNetwork], process.env.REACT_APP_SERVER_MNEMONIC);
|
|
54
54
|
const prosopoServer = new ProsopoServer(config, pair);
|
|
55
55
|
app.use(routesFactory(mongoose, prosopoServer));
|
|
56
56
|
app.listen(process.env.REACT_APP_SERVER_PORT);
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,iBAAiB,MAAM,uBAAuB,CAAA;AACrD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,iBAAiB,MAAM,qBAAqB,CAAA;AACnD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAE9C,MAAM,UAAU,OAAO;IACnB,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,QAAQ,GAAG,MAAM,EAAE,QAAQ,GAAG,IAAI;IACzD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAA;IACjD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AM,MAAM,GAAG,eAAe,EAAE,CAAA;IAEhC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC7B,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAA;IAC9G,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAErD,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAA;IAE/C,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;AACjD,CAAC;AAED,IAAI,EAAE;KACD,IAAI,CAAC,GAAG,EAAE;IACP,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;AACjC,CAAC,CAAC;KACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACX,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,IAAI,EAAE,CAAA;AAClB,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAoB/C,QAAA,MAAM,MAAM,aACE,UAAU,iBACL,aAAa,OACvB,OAAO,OACP,QAAQ,QACP,YAAY,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/controllers/auth.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA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AC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAA;KACpD;SAAM;QACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC,CAAA;KAC7D;AACL,CAAC,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAaA,OAAO,QAAoB,MAAM,UAAU,CAAA;AAE3C,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACf;AAED,QAAA,MAAM,UAAU;;;;
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAaA,OAAO,QAAoB,MAAM,UAAU,CAAA;AAE3C,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACf;AAED,QAAA,MAAM,UAAU;;;;EAmBd,CAAA;AAEF,eAAe,UAAU,CAAA"}
|
package/dist/models/user.js
CHANGED
package/dist/models/user.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/models/user.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEA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,MAAM;KACpC;IACD,IAAI,EAAE;QACF,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;QACjC,QAAQ,EAAE,IAAI;KACjB;CACJ,CAAC,CAAA;AAEF,eAAe,UAAU,CAAA"}
|
package/env.development
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
REACT_APP_API_PATH_PREFIX=/v1/prosopo
|
|
2
|
+
REACT_APP_DAPP_SITE_KEY=5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw
|
|
3
|
+
REACT_APP_SUBSTRATE_NODE_URL=ws://localhost:9944
|
|
4
|
+
REACT_APP_PROSOPO_CONTRACT_ADDRESS=
|
|
5
|
+
REACT_APP_WEB2=true
|
|
6
|
+
REACT_APP_SERVER_URL=https://localhost
|
|
7
|
+
REACT_APP_SERVER_MNEMONIC=//Bob
|
|
8
|
+
REACT_APP_SERVER_ACCOUNT_ADDRESS=
|
|
9
|
+
REACT_APP_SERVER_PORT=9228
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/client-example-server",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "Backend for client-example",
|
|
5
5
|
"main": "dist/app.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"dev": "vite serve --mode=development --config ./vite.config.ts --host",
|
|
13
|
-
"start": "node ./dist/
|
|
14
|
-
"
|
|
15
|
-
"build
|
|
16
|
-
"
|
|
13
|
+
"start": "node ./dist/app.js",
|
|
14
|
+
"start:bundle": "node ./dist/bundle/prosopo_client_example_server.app.bundle.js",
|
|
15
|
+
"build": "tsc --build --verbose",
|
|
16
|
+
"bundle:prod": "vite build --mode=production --config ./vite.config.ts",
|
|
17
|
+
"bundle:dev": "vite build --mode=development --config ./vite.config.ts",
|
|
17
18
|
"clean": "tsc --build --clean",
|
|
18
19
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
19
20
|
"lint:fix": "npx eslint . --fix"
|
|
@@ -30,15 +31,14 @@
|
|
|
30
31
|
"homepage": "https://github.com/prosopo/client-example-server#readme",
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"@noble/hashes": "^1.3.1",
|
|
33
|
-
"@polkadot/util": "12.
|
|
34
|
-
"@polkadot/util-crypto": "12.
|
|
35
|
-
"@prosopo/api": "0.2.
|
|
36
|
-
"@prosopo/contract": "0.2.
|
|
37
|
-
"@prosopo/procaptcha": "0.2.
|
|
38
|
-
"@prosopo/server": "0.2.
|
|
39
|
-
"@prosopo/types": "0.2.
|
|
34
|
+
"@polkadot/util": "12.5.1",
|
|
35
|
+
"@polkadot/util-crypto": "12.5.1",
|
|
36
|
+
"@prosopo/api": "0.2.14",
|
|
37
|
+
"@prosopo/contract": "0.2.14",
|
|
38
|
+
"@prosopo/procaptcha": "0.2.14",
|
|
39
|
+
"@prosopo/server": "0.2.14",
|
|
40
|
+
"@prosopo/types": "0.2.14",
|
|
40
41
|
"@typegoose/auto-increment": "3.3.0",
|
|
41
|
-
"axios": "^1.5.0",
|
|
42
42
|
"cors": "^2.8.5",
|
|
43
43
|
"jsonwebtoken": "^9.0.0",
|
|
44
44
|
"mongoose": "^7.3.3",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"ts-node": "^10.9.1",
|
|
52
52
|
"tslib": "2.6.2",
|
|
53
53
|
"typescript": "5.1.6",
|
|
54
|
-
"vite": "^4.
|
|
55
|
-
"@prosopo/config": "0.2.
|
|
54
|
+
"vite": "^4.5.0",
|
|
55
|
+
"@prosopo/config": "0.2.14"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/src/app.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { ProsopoServer, getServerConfig } from '@prosopo/server'
|
|
15
|
+
import { getPairAsync } from '@prosopo/contract'
|
|
16
|
+
import connectionFactory from './utils/connection.js'
|
|
17
|
+
import cors from 'cors'
|
|
18
|
+
import dotenv from 'dotenv'
|
|
19
|
+
import express from 'express'
|
|
20
|
+
import memoryServerSetup from './utils/database.js'
|
|
21
|
+
import path from 'path'
|
|
22
|
+
import routesFactory from './routes/routes.js'
|
|
23
|
+
|
|
24
|
+
export function loadEnv() {
|
|
25
|
+
dotenv.config({ path: getEnvFile() })
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getEnvFile(filename = '.env', filepath = './') {
|
|
29
|
+
const env = process.env.NODE_ENV || 'development'
|
|
30
|
+
return path.join(filepath, `${filename}.${env}`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function main() {
|
|
34
|
+
loadEnv()
|
|
35
|
+
|
|
36
|
+
const app = express()
|
|
37
|
+
|
|
38
|
+
app.use(cors({ origin: true, credentials: true }))
|
|
39
|
+
|
|
40
|
+
app.use(express.urlencoded({ extended: true }))
|
|
41
|
+
|
|
42
|
+
app.use(express.json())
|
|
43
|
+
|
|
44
|
+
app.use((_, res, next) => {
|
|
45
|
+
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
46
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE')
|
|
47
|
+
res.setHeader('Access-Control-Allow-Headers', 'Origin, Content-Type, X-Auth-Token, Authorization')
|
|
48
|
+
next()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
app.options('/*', (_, res) => {
|
|
52
|
+
res.sendStatus(200)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const uri = await memoryServerSetup()
|
|
56
|
+
console.log('mongo uri', uri)
|
|
57
|
+
const mongoose = connectionFactory(uri)
|
|
58
|
+
if (!process.env.REACT_APP_SERVER_MNEMONIC) {
|
|
59
|
+
throw new Error('No mnemonic found')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const config = getServerConfig()
|
|
63
|
+
|
|
64
|
+
console.log('config', config)
|
|
65
|
+
const pair = await getPairAsync(config.networks[config.defaultNetwork], process.env.REACT_APP_SERVER_MNEMONIC)
|
|
66
|
+
const prosopoServer = new ProsopoServer(config, pair)
|
|
67
|
+
|
|
68
|
+
app.use(routesFactory(mongoose, prosopoServer))
|
|
69
|
+
|
|
70
|
+
app.listen(process.env.REACT_APP_SERVER_PORT)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main()
|
|
74
|
+
.then(() => {
|
|
75
|
+
console.log('Server started')
|
|
76
|
+
})
|
|
77
|
+
.catch((err) => {
|
|
78
|
+
console.log(err)
|
|
79
|
+
process.exit()
|
|
80
|
+
})
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { ApiParams } from '@prosopo/types'
|
|
15
|
+
import { Connection } from 'mongoose'
|
|
16
|
+
import { NextFunction, Request, Response } from 'express'
|
|
17
|
+
import { ProcaptchaResponse } from '@prosopo/types'
|
|
18
|
+
import { ProsopoServer } from '@prosopo/server'
|
|
19
|
+
import { UserInterface } from '../models/user.js'
|
|
20
|
+
import { at } from '@prosopo/util'
|
|
21
|
+
import { blake2b } from '@noble/hashes/blake2b'
|
|
22
|
+
import { randomAsHex } from '@polkadot/util-crypto'
|
|
23
|
+
import { u8aToHex } from '@polkadot/util'
|
|
24
|
+
import { z } from 'zod'
|
|
25
|
+
import jwt from 'jsonwebtoken'
|
|
26
|
+
|
|
27
|
+
const SubscribeBodySpec = ProcaptchaResponse.merge(
|
|
28
|
+
z.object({
|
|
29
|
+
email: z.string().email(),
|
|
30
|
+
password: z.string(),
|
|
31
|
+
})
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
function hashPassword(password: string): string {
|
|
35
|
+
return u8aToHex(blake2b(password))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const signup = async (
|
|
39
|
+
mongoose: Connection,
|
|
40
|
+
prosopoServer: ProsopoServer,
|
|
41
|
+
req: Request,
|
|
42
|
+
res: Response,
|
|
43
|
+
next: NextFunction
|
|
44
|
+
) => {
|
|
45
|
+
try {
|
|
46
|
+
const User = mongoose.model<UserInterface>('User')
|
|
47
|
+
// checks if email exists
|
|
48
|
+
const dbUser = await User.findOne({
|
|
49
|
+
email: req.body.email,
|
|
50
|
+
})
|
|
51
|
+
const payload = SubscribeBodySpec.parse(req.body)
|
|
52
|
+
await prosopoServer.isReady()
|
|
53
|
+
if (dbUser) {
|
|
54
|
+
return res.status(409).json({ message: 'email already exists' })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
|
|
58
|
+
// salt
|
|
59
|
+
const salt = randomAsHex(32)
|
|
60
|
+
// !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
|
|
61
|
+
const passwordHash = hashPassword(`${req.body.password}${salt}`)
|
|
62
|
+
if (passwordHash) {
|
|
63
|
+
return User.create({
|
|
64
|
+
email: req.body.email,
|
|
65
|
+
name: req.body.name,
|
|
66
|
+
password: passwordHash,
|
|
67
|
+
salt: salt,
|
|
68
|
+
})
|
|
69
|
+
.then(() => {
|
|
70
|
+
res.status(200).json({ message: 'user created' })
|
|
71
|
+
})
|
|
72
|
+
.catch((err) => {
|
|
73
|
+
console.log(err)
|
|
74
|
+
res.status(502).json({ message: 'error while creating the user' })
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
res.status(401).json({ message: 'user has not completed a captcha' })
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.error('error', err)
|
|
82
|
+
res.status(500).json({ message: (err as Error).message || 'internal server error' })
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const login = async (mongoose: Connection, prosopoServer: ProsopoServer, req: Request, res: Response) => {
|
|
87
|
+
const User = mongoose.model<UserInterface>('User')
|
|
88
|
+
await prosopoServer.isReady()
|
|
89
|
+
// checks if email exists
|
|
90
|
+
await User.findOne({
|
|
91
|
+
email: req.body.email,
|
|
92
|
+
})
|
|
93
|
+
.then(async (dbUser) => {
|
|
94
|
+
if (!dbUser) {
|
|
95
|
+
res.status(404).json({ message: 'user not found' })
|
|
96
|
+
} else {
|
|
97
|
+
const payload = SubscribeBodySpec.parse(req.body)
|
|
98
|
+
if (await prosopoServer.isVerified(payload[ApiParams.procaptchaResponse])) {
|
|
99
|
+
// password hash
|
|
100
|
+
// !!!DUMMY CODE!!! - Do not use in production. Use bcrypt or similar for password hashing.
|
|
101
|
+
const passwordHash = hashPassword(`${req.body.password}${dbUser.salt}`)
|
|
102
|
+
if (passwordHash !== dbUser.password) {
|
|
103
|
+
// password doesnt match
|
|
104
|
+
res.status(401).json({ message: 'invalid credentials' })
|
|
105
|
+
} else {
|
|
106
|
+
// password match
|
|
107
|
+
const token = jwt.sign({ email: req.body.email }, 'secret', { expiresIn: '1h' })
|
|
108
|
+
res.status(200).json({ message: 'user logged in', token: token })
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
.catch((err) => {
|
|
114
|
+
console.error('error', err)
|
|
115
|
+
res.status(500).json({ message: err.message || 'internal server error' })
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const isAuth = (req: Request, res: Response) => {
|
|
120
|
+
const authHeader = req.get('Authorization') || ''
|
|
121
|
+
if (!authHeader) {
|
|
122
|
+
res.status(401).json({ message: 'not authenticated' })
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const token = at(authHeader.split(' '), 1)
|
|
126
|
+
let decodedToken
|
|
127
|
+
try {
|
|
128
|
+
decodedToken = jwt.verify(token, 'secret')
|
|
129
|
+
} catch (err) {
|
|
130
|
+
res.status(500).json({ message: (err as Error).message || 'could not decode the token' })
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!decodedToken) {
|
|
134
|
+
res.status(401).json({ message: 'unauthorized' })
|
|
135
|
+
} else {
|
|
136
|
+
res.status(200).json({ message: 'here is your resource' })
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export { signup, login, isAuth }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import mongoose, { Schema } from 'mongoose'
|
|
15
|
+
|
|
16
|
+
export interface UserInterface {
|
|
17
|
+
id: number
|
|
18
|
+
email: string
|
|
19
|
+
name: string
|
|
20
|
+
password: string
|
|
21
|
+
salt: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const UserSchema = new Schema<UserInterface>({
|
|
25
|
+
email: {
|
|
26
|
+
type: mongoose.SchemaTypes.String,
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
name: {
|
|
30
|
+
type: mongoose.SchemaTypes.String,
|
|
31
|
+
},
|
|
32
|
+
password: {
|
|
33
|
+
type: mongoose.SchemaTypes.String,
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
id: {
|
|
37
|
+
type: mongoose.SchemaTypes.Number,
|
|
38
|
+
},
|
|
39
|
+
salt: {
|
|
40
|
+
type: mongoose.SchemaTypes.String,
|
|
41
|
+
required: true,
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
export default UserSchema
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { Connection } from 'mongoose'
|
|
15
|
+
import { ProsopoServer } from '@prosopo/server'
|
|
16
|
+
import { isAuth, login, signup } from '../controllers/auth.js'
|
|
17
|
+
import express from 'express'
|
|
18
|
+
|
|
19
|
+
const router = express.Router()
|
|
20
|
+
|
|
21
|
+
function getRoutes(mongoose: Connection, prosopoServer: ProsopoServer): express.Router {
|
|
22
|
+
router.post('/login', login.bind(null, mongoose, prosopoServer))
|
|
23
|
+
|
|
24
|
+
router.post('/signup', signup.bind(null, mongoose, prosopoServer))
|
|
25
|
+
|
|
26
|
+
router.get('/private', isAuth)
|
|
27
|
+
|
|
28
|
+
router.get('/public', (req, res) => {
|
|
29
|
+
res.status(200).json({ message: 'here is your public resource' })
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// will match any other path
|
|
33
|
+
router.use('/', (req, res) => {
|
|
34
|
+
res.status(404).json({ error: 'page not found' })
|
|
35
|
+
})
|
|
36
|
+
return router
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default getRoutes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { AutoIncrementID, AutoIncrementIDOptions } from '@typegoose/auto-increment'
|
|
15
|
+
import UserSchema from '../models/user.js'
|
|
16
|
+
import mongoose, { Connection } from 'mongoose'
|
|
17
|
+
|
|
18
|
+
function connectionFactory(uri: string): Connection {
|
|
19
|
+
const conn = mongoose.createConnection(uri)
|
|
20
|
+
if (!conn.models.user) {
|
|
21
|
+
UserSchema.plugin(AutoIncrementID, { field: 'id' } as AutoIncrementIDOptions)
|
|
22
|
+
conn.model('User', UserSchema)
|
|
23
|
+
}
|
|
24
|
+
return conn
|
|
25
|
+
}
|
|
26
|
+
export default connectionFactory
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { MongoMemoryServer } from 'mongodb-memory-server'
|
|
15
|
+
export async function memoryServerSetup(): Promise<string> {
|
|
16
|
+
const mongod = MongoMemoryServer.create()
|
|
17
|
+
const memoryServer = await mongod
|
|
18
|
+
return memoryServer.getUri()
|
|
19
|
+
}
|
|
20
|
+
export default memoryServerSetup
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.esm.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"lib": ["dom", "dom.iterable", "esnext"]
|
|
7
|
+
},
|
|
8
|
+
"include": ["src", "src/**/*.json"],
|
|
9
|
+
"references": [
|
|
10
|
+
{
|
|
11
|
+
"path": "../../packages/api"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"path": "../../packages/cli"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "../../packages/contract"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "../../packages/procaptcha"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "../../packages/server"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "../../packages/types"
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|