-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from smritidoneria/main
fixes
- Loading branch information
Showing
7 changed files
with
181 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { connectMongoDB } from "@/lib/mongodb"; | ||
import { Users } from "@/models/user.js"; | ||
import { getTokenDetails } from "@/utils/authuser.js"; | ||
import { getToken } from "next-auth/jwt"; | ||
import { headers } from 'next/headers'; | ||
import { NextResponse } from "next/server"; | ||
|
||
|
||
export async function POST(req){ | ||
try{ | ||
await connectMongoDB(); | ||
const headersList = headers() | ||
// const authorization = headersList.get('authorization') | ||
const token = await getToken({req}) | ||
//console.log('ff', token) | ||
console.log(token.accessTokenFromBackend); | ||
// const auth = req.headers.get("authorization").split(' ')[1]; | ||
|
||
let userId = await getTokenDetails(token.accessTokenFromBackend); | ||
console.log(userId); | ||
const user=await Users.findById(userId); | ||
console.log(user); | ||
|
||
const {regNo,mobno}=await req.json(); | ||
|
||
await Users.findByIdAndUpdate(userId,{$set:{regNo:regNo,mobno:mobno}}) | ||
// console.log(newUserDetail); | ||
// const { accessToken, refreshToken } = await generateTokens(newUserDetail); | ||
// console.log(accessToken); | ||
// console.log(refreshToken); | ||
|
||
//console.log(accessToken); | ||
|
||
return NextResponse.json({ message: "User Details entered ", status: 200 }); | ||
|
||
|
||
}catch(error) { | ||
console.error("An error occurred:", error); | ||
return NextResponse.json({ message: "Error occurred ", status: 500 }); | ||
} | ||
|
||
} |
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,103 @@ | ||
"use client" | ||
import { useState } from 'react'; | ||
import { useSession } from 'next-auth/react'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
export default function UserDetails() { | ||
const { data: session, status } = useSession(); | ||
|
||
// use session chl rha h baaki frondend me data kese lena h aap log dekh lo | ||
//console.log("fsdbhbsbvdfwad",data); | ||
// console.log("fgfcgcgfdfdsds",session); | ||
//console.log(data); | ||
|
||
const [firstName, setFirstName] = useState(''); | ||
const [lastName, setLastName] = useState(''); | ||
const [regNo, setRegNo] = useState(''); | ||
const [mobno, setMobno] = useState(''); | ||
// const router = useRouter(); | ||
|
||
const handleSubmit = async () => { | ||
|
||
console.log('button ') | ||
|
||
try { | ||
const response = await fetch('http://localhost:3001/api/login', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
Authorization:`Bearer ${session.accessTokenBackend}`, | ||
'Access-Control-Allow-Origin':'*', | ||
body: JSON.stringify({ | ||
firstName, | ||
lastName, | ||
regNo, | ||
mobno | ||
}) | ||
}); | ||
|
||
if (response.ok) { | ||
console.log('Data saved successfully'); | ||
|
||
setFirstName(''); | ||
setLastName(''); | ||
setRegNo(''); | ||
setMobno(''); | ||
|
||
// router.push('/') | ||
|
||
} else { | ||
console.error('Failed to save data:', response.statusText); | ||
} | ||
} catch (error) { | ||
console.error('Error saving data:', error); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<label htmlFor="firstName">First Name:</label> | ||
<input | ||
type="text" | ||
id="firstName" | ||
value={firstName} | ||
onChange={(e) => setFirstName(e.target.value)} | ||
style={{ color: 'black' }} | ||
/> | ||
</div> | ||
<div> | ||
<label htmlFor="lastName">Last Name:</label> | ||
<input | ||
type="text" | ||
id="lastName" | ||
value={lastName} | ||
onChange={(e) => setLastName(e.target.value)} | ||
style={{ color: 'black' }} | ||
/> | ||
</div> | ||
<div> | ||
<label htmlFor="regNo">Registration Number:</label> | ||
<input | ||
type="text" | ||
id="regNo" | ||
value={regNo} | ||
onChange={(e) => setRegNo(e.target.value)} | ||
style={{ color: 'black' }} | ||
/> | ||
</div> | ||
<div> | ||
<label htmlFor="mobNo">Mobile Number:</label> | ||
<input | ||
type="text" | ||
id="mobNo" | ||
value={mobno} | ||
onChange={(e) => setMobno(e.target.value)} | ||
style={{ color: 'black' }} | ||
/> | ||
</div> | ||
<button onClick={()=>handleSubmit()}>Submit</button> | ||
</div> | ||
); | ||
} |
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