-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'subhadeeproy3902:main' into multilanguage
- Loading branch information
Showing
75 changed files
with
2,494 additions
and
396 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,56 @@ | ||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
|
||
type UserState = { | ||
id: string; | ||
firstName: string; | ||
lastName: string; | ||
email: string; | ||
refreshToken: string; | ||
accessToken: string; | ||
image: string | undefined; | ||
}; | ||
|
||
type AuthState = { | ||
user:{ | ||
isAuth: boolean; | ||
id:string; | ||
firstName: string; | ||
lastName: string; | ||
email: string; | ||
refreshToken:string; | ||
accessToken:string; | ||
image:string | undefined; | ||
} | ||
}; | ||
|
||
const initialState: AuthState = { | ||
user:{ | ||
id:"", | ||
isAuth: false, | ||
firstName: "", | ||
lastName: "", | ||
email: "", | ||
accessToken: "", | ||
refreshToken: "", | ||
image:undefined | ||
} | ||
}; | ||
|
||
export const auth = createSlice({ | ||
name: "auth", | ||
initialState:initialState, | ||
reducers: { | ||
logOut: (state) => { | ||
state.user = { ...initialState.user }; | ||
}, | ||
logIn: (state, action: PayloadAction<UserState>) => { | ||
state.user = { | ||
...action.payload, | ||
isAuth: true, | ||
}; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { logIn, logOut } = auth.actions; | ||
export default auth.reducer; |
File renamed without changes.
File renamed without changes.
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 @@ | ||
"use client"; | ||
import { Provider } from "react-redux"; | ||
import { persistor, store } from "../config/store"; | ||
import { PersistGate } from 'redux-persist/integration/react' | ||
|
||
export function ReduxProviders({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<Provider store={store}> | ||
<PersistGate persistor={persistor}> | ||
{children} | ||
</PersistGate> | ||
</Provider> | ||
); | ||
} |
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,5 @@ | ||
"use client"; | ||
import { SessionProvider } from "next-auth/react"; | ||
export const AuthProvider = ({ children }: { children: React.ReactNode; }) => { | ||
return <SessionProvider>{children}</SessionProvider>; | ||
}; |
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,87 @@ | ||
import type { NextAuthOptions } from "next-auth"; | ||
import CredentialsProvider from "next-auth/providers/credentials"; | ||
import UserModel from "@/models/user"; | ||
import bcrypt from "bcryptjs"; | ||
import { mongoDB } from "@/lib/MongoDB"; | ||
|
||
export const options: NextAuthOptions = { | ||
providers: [ | ||
CredentialsProvider({ | ||
name: "Credentials", | ||
credentials: { | ||
email: { | ||
label: "email:", | ||
type: "text", | ||
placeholder: "your-cool-email", | ||
}, | ||
password: { | ||
label: "Password:", | ||
type: "password", | ||
placeholder: "your-awesome-password", | ||
}, | ||
}, | ||
async authorize(credentials) { | ||
//retrieve user data | ||
const { email, password }: any = credentials; | ||
try { | ||
await mongoDB(); | ||
const user = await UserModel.findOne({ email }); | ||
if (!user) { | ||
throw new Error("Not Registered!"); | ||
} | ||
const passCheck = await bcrypt.compare(password, user.password); | ||
|
||
if (!passCheck) throw new Error("Incorrect Password!"); | ||
|
||
return user; | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
}, | ||
}), | ||
], | ||
session:{ | ||
strategy:"jwt", | ||
}, | ||
pages: { | ||
signIn: "/signin", | ||
}, | ||
secret: process.env.NEXTAUTH_SECRET, | ||
callbacks:{ | ||
async session({ session, token }) { | ||
session.user = { | ||
...session.user, | ||
id: token.id as string, | ||
email: token.email as string, | ||
accessToken: token.accessToken as string, | ||
refreshToken: token.refreshToken as string, | ||
firstName: token.firstName as string, | ||
lastName: token.lastName as string, | ||
image: token.image as string | undefined, | ||
}; | ||
return session; | ||
}, | ||
async jwt({ token, user }:any) { | ||
if (user) { | ||
// Generate access and refresh tokens when the user is defined | ||
const accessToken = user.generateAccessToken(); | ||
const refreshToken = user.generateRefreshToken(); | ||
|
||
// Save the refresh token to the user document | ||
user.refreshToken = refreshToken; | ||
await user.save({ validateBeforeSave: false }); | ||
|
||
token.id = user._id; | ||
token.email = user.email; | ||
token.firstName = user.firstName; | ||
token.lastName = user.lastName; | ||
|
||
token.accessToken = accessToken; | ||
token.refreshToken = refreshToken; | ||
|
||
token.image = user.image | ||
} | ||
return token; | ||
} | ||
}, | ||
}; |
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,6 @@ | ||
import NextAuth from "next-auth" | ||
import { options } from "./options" | ||
|
||
const handler = NextAuth(options); | ||
|
||
export { handler as GET, handler as POST } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.