This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96e9b68
commit 4e9630f
Showing
29 changed files
with
473 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { NowRequest, NowResponse } from '@vercel/node'; | ||
import { connect } from 'mongoose'; | ||
import { connection } from 'mongoose'; | ||
|
||
const { | ||
MONGO_USER, | ||
MONGO_PASSWORD, | ||
} = process.env; | ||
import { connectDB } from '../utils/db'; | ||
connectDB(); | ||
|
||
connect(`mongodb+srv://${MONGO_USER}:${MONGO_PASSWORD}@cluster0.oj6kf.mongodb.net/proactive?retryWrites=true&w=majority`, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
import { Item } from '../models'; | ||
import { verifyToken } from '../utils/auth'; | ||
|
||
export default async function (req: NowRequest, res: NowResponse) { | ||
return res.status(200).send('Hello'); | ||
let user = await verifyToken(req); | ||
|
||
let items = await Item.find({ | ||
user, | ||
}); | ||
|
||
connection.close(); | ||
return res.status(200).send(items); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { NowRequest, NowResponse } from '@vercel/node'; | ||
import { connection } from 'mongoose'; | ||
|
||
import { connectDB } from '../utils/db'; | ||
connectDB(); | ||
|
||
import { User } from '../models'; | ||
import { register } from '../utils/auth'; | ||
|
||
export default async function (req: NowRequest, res: NowResponse) { | ||
try { | ||
const existingUser = await User.findOne({ | ||
username: req.body.username | ||
}); | ||
|
||
if (existingUser) { | ||
return res.status(400).send('Username taken'); | ||
} | ||
|
||
let user = new User({ | ||
username: req.body.username, | ||
password: req.body.password, | ||
}); | ||
|
||
await user.save(); | ||
|
||
return await register(user, res, connection); | ||
} catch (error) { | ||
connection.close(); | ||
return res.status(502).send(error); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { User } from './User'; | ||
export { Item } from './Item'; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import axios from 'axios'; | ||
|
||
export default { | ||
async getUser() { | ||
let response = await axios.get('/api/check-user'); | ||
return response.data; | ||
}, | ||
async login(payload) { | ||
let response = await axios.put('/api/login', payload); | ||
return response.data; | ||
}, | ||
async register(payload) { | ||
let response = await axios.put('/api/register', payload); | ||
return response.data; | ||
}, | ||
async logout() { | ||
let response = await axios.put('/api/logout'); | ||
return response.data; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import auth from './auth'; | ||
import items from './items'; | ||
|
||
export default { | ||
auth, | ||
items, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default { | ||
getItems() { | ||
return []; | ||
}, | ||
getItem() { | ||
return 0; | ||
}, | ||
editItem() { | ||
return 0; | ||
}, | ||
deleteItem() { | ||
return 0; | ||
}, | ||
}; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.