|
|
@@ -41,12 +41,12 @@ exports.login = handleError(async (req, res) => {
|
|
|
user_id: user.id,
|
|
|
})
|
|
|
let role = null
|
|
|
- if (process.env.ENV === 'production') {
|
|
|
- role = user.peran.filter((e) => roleDataProduction.includes(e.peran.id))[0]
|
|
|
- role.peran.id = convertRole(role.peran.id)
|
|
|
- } else {
|
|
|
- role = user.peran.filter((e) => roleDataProduction.includes(e.peran.id))[0]
|
|
|
- }
|
|
|
+ //if (process.env.ENV === 'production') {
|
|
|
+ role = user.peran.filter((e) => roleDataProduction.includes(e.peran.id))[0]
|
|
|
+ role.peran.id = convertRole(role.peran.id)
|
|
|
+ /*} else {
|
|
|
+ role = user.peran.filter((e) => roleData.includes(e.peran.id))[0]
|
|
|
+ }*/
|
|
|
let dataRole = {
|
|
|
id: role.peran.id,
|
|
|
nama: role.peran.nama,
|
|
|
@@ -65,22 +65,22 @@ exports.login = handleError(async (req, res) => {
|
|
|
isPrivate: false,
|
|
|
})
|
|
|
} else {
|
|
|
- if (process.env.ENV === 'production') {
|
|
|
- if (cekUser.role.id !== role.peran.id) {
|
|
|
- await userModel.updateOne({ _id: cekUser._id }, { role: dataRole })
|
|
|
- }
|
|
|
- if (!cekUser.lembaga) {
|
|
|
- await userModel.updateOne(
|
|
|
- { _id: cekUser._id },
|
|
|
- { lembaga: role.organisasi }
|
|
|
- )
|
|
|
- }
|
|
|
- if (cekUser.role.id !== role.peran.id || !cekUser.lembaga) {
|
|
|
- cekUser = await userModel.findOne({
|
|
|
- user_id: user.id,
|
|
|
- })
|
|
|
- }
|
|
|
+ //if (process.env.ENV === 'production') {
|
|
|
+ if (cekUser.role.id !== role.peran.id) {
|
|
|
+ await userModel.updateOne({ _id: cekUser._id }, { role: dataRole })
|
|
|
+ }
|
|
|
+ if (!cekUser.lembaga) {
|
|
|
+ await userModel.updateOne(
|
|
|
+ { _id: cekUser._id },
|
|
|
+ { lembaga: role.organisasi }
|
|
|
+ )
|
|
|
}
|
|
|
+ if (cekUser.role.id !== role.peran.id || !cekUser.lembaga) {
|
|
|
+ cekUser = await userModel.findOne({
|
|
|
+ user_id: user.id,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
const accessToken = jwt.sign({ _id: cekUser._id }, process.env.SECRET, {
|
|
|
@@ -93,7 +93,10 @@ exports.login = handleError(async (req, res) => {
|
|
|
const now = new Date()
|
|
|
const time = now.getTime()
|
|
|
now.setTime(time + 24 * 60 * 60 * 1000)
|
|
|
- res.cookie('sidali-cookie', accessToken, { httpOnly: true, expires: now })
|
|
|
+ res.cookie('sidali-cookie', accessToken, {
|
|
|
+ httpOnly: true,
|
|
|
+ expires: now,
|
|
|
+ })
|
|
|
|
|
|
response.success(res, {
|
|
|
message: 'Berhasil Login',
|
|
|
@@ -102,7 +105,9 @@ exports.login = handleError(async (req, res) => {
|
|
|
})
|
|
|
|
|
|
exports.logout = (req, res) => {
|
|
|
- res.cookie('sidali-cookie', '', { expires: new Date() })
|
|
|
+ res.cookie('sidali-cookie', '', {
|
|
|
+ expires: new Date(),
|
|
|
+ })
|
|
|
|
|
|
response.success(res, {
|
|
|
message: 'Berhasil Logout',
|