Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
travel
Commits
ed7b303c
Commit
ed7b303c
authored
Jul 26, 2022
by
Yoon, Daeki
😅
Browse files
user role 추가
parent
5d59e60d
Changes
6
Show whitespace changes
Inline
Side-by-side
frontend/src/home/header.tsx
View file @
ed7b303c
...
...
@@ -5,7 +5,7 @@ import { useAuth } from "../auth/auth.context";
import
"
tailwindcss/tailwind.css
"
;
export
default
function
Header
()
{
const
{
logout
}
=
useAuth
();
const
{
logout
,
user
}
=
useAuth
();
const
[
search
,
setSearch
]
=
useState
(
""
);
const
handleChange
=
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
...
...
@@ -33,7 +33,7 @@ export default function Header() {
</
div
>
</
div
>
<
div
className
=
"flex justify-end "
>
{
useAuth
().
user
.
isLoggedIn
?
(
{
user
.
isLoggedIn
?
(
<
div
className
=
"flex text-xs"
>
<
Link
to
=
"/profile"
className
=
"mr-2 "
>
프로필
...
...
src/controllers/auth.controller.ts
View file @
ed7b303c
...
...
@@ -70,6 +70,7 @@ export const login = asyncWrap(async (req, res) => {
res
.
json
({
isLoggedIn
:
true
,
email
:
user
.
email
,
role
:
user
.
role
?.
name
,
});
});
...
...
src/db/user.db.ts
View file @
ed7b303c
import
bcrypt
from
"
bcryptjs
"
;
import
{
ObjectId
}
from
"
mongoose
"
;
import
{
IUser
,
Role
,
Post
,
User
,
FileInfo
}
from
"
../models
"
;
import
{
IUser
,
Role
,
Post
,
User
,
FileInfo
,
IRole
}
from
"
../models
"
;
import
fs
from
"
fs/promises
"
;
export
const
createUser
=
async
(
user
:
IUser
)
=>
{
// 비밀번호 암호화
const
hash
=
await
bcrypt
.
hash
(
user
.
password
,
10
);
const
newFileInfo
=
await
FileInfo
.
create
({});
//
const newFileInfo = await FileInfo.create({});
// 사용자 역할 추가: 기본값은 "user"
let
userRole
=
null
;
if
(
user
.
role
)
{
...
...
@@ -19,7 +19,7 @@ export const createUser = async (user: IUser) => {
password
:
hash
,
role
:
userRole
,
isNew
:
true
,
fileInfo
:
newFileInfo
.
_id
,
//
fileInfo: newFileInfo._id,
});
const
retUser
=
await
newUser
.
save
();
return
retUser
;
...
...
@@ -31,9 +31,11 @@ export const findUserByEmail = async (
)
=>
{
let
user
;
if
(
includePassword
)
{
user
=
await
User
.
findOne
({
email
}).
select
(
"
+password
"
);
user
=
await
User
.
findOne
({
email
})
.
select
(
"
+password
"
)
.
populate
<
{
role
:
IRole
}
>
(
"
role
"
);
}
else
{
user
=
await
User
.
findOne
({
email
});
user
=
await
User
.
findOne
({
email
})
.
populate
<
{
role
:
IRole
}
>
(
"
role
"
)
;
}
return
user
;
};
...
...
src/models/index.ts
View file @
ed7b303c
export
{
default
as
User
,
IUser
}
from
"
./user.model
"
;
export
{
default
as
Post
,
PostType
}
from
"
./post.model
"
;
export
{
default
as
Role
}
from
"
./role.model
"
;
export
{
default
as
Role
,
IRole
}
from
"
./role.model
"
;
export
{
default
as
FileInfo
,
IFileInfo
}
from
"
./fileinfo.model
"
;
export
{
default
as
Mainimg
,
MainimgType
}
from
"
./mainimg.model
"
;
src/models/role.model.ts
View file @
ed7b303c
import
{
model
,
Schema
}
from
"
mongoose
"
;
interface
IRole
{
export
interface
IRole
{
name
:
string
;
priority
:
number
;
}
...
...
src/models/user.model.ts
View file @
ed7b303c
import
{
model
,
Schema
,
Types
,
version
}
from
"
mongoose
"
;
import
{
model
,
Schema
,
Types
}
from
"
mongoose
"
;
export
interface
IUser
{
email
:
string
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment