-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
367 additions
and
29 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 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
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,43 @@ | ||
import dbConnect from '../../../../utils/dbConnect'; | ||
import userSchema from '../../../../utils/models/userSchema' | ||
|
||
dbConnect(); | ||
|
||
export default async function handler(req, res) { | ||
|
||
if (req.method !== 'POST') { | ||
return res.status(500).json({ message: 'Soory this is post route' }) | ||
} | ||
|
||
const { userId, urlId } = req.body; | ||
|
||
const filter = { _id: userId }; | ||
|
||
const user = await userSchema.findOne(filter); | ||
|
||
if (!user) { | ||
return res.status(423).send({ success: false }) | ||
} | ||
|
||
try { | ||
|
||
if (!user.links.includes(urlId)) { | ||
return res.status(423).send({ success: false, response: "Url does not exist" }) | ||
} | ||
|
||
var index = user.links.indexOf(urlId); | ||
|
||
user.links.splice(index, 1); | ||
await user.save(); | ||
|
||
return res.status(200).send({ success: true }) | ||
} | ||
catch (e) { | ||
console.log(e) | ||
return res.status(423).send({ success: false }) | ||
} | ||
|
||
return res.status(423).send({ success: false }) | ||
|
||
|
||
} |
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 |
---|---|---|
|
@@ -2,8 +2,9 @@ import Head from 'next/head'; | |
import Navbar from '../components/Navbar'; | ||
import Main from '../components/Main'; | ||
import { Context } from '../context/Store' | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import React, { useContext, useEffect} from 'react'; | ||
import { getCookie, removeCookies } from 'cookies-next'; | ||
import Script from 'next/script' | ||
|
||
export default function Home() { | ||
|
||
|
@@ -62,7 +63,6 @@ export default function Home() { | |
const setAuthData = async () => { | ||
|
||
const authData = await getUserData(); | ||
console.log(authData); | ||
await setState(prevState => ({ | ||
...prevState, | ||
['user']: authData, | ||
|
@@ -78,8 +78,9 @@ export default function Home() { | |
<Head> | ||
<title>Shwt</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
</Head> | ||
|
||
</Head> | ||
<Script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" | ||
crossOrigin="anonymous"></Script> | ||
<Navbar /> | ||
<Main /> | ||
</div> | ||
|
Oops, something went wrong.