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";
...
@@ -5,7 +5,7 @@ import { useAuth } from "../auth/auth.context";
import
"
tailwindcss/tailwind.css
"
;
import
"
tailwindcss/tailwind.css
"
;
export
default
function
Header
()
{
export
default
function
Header
()
{
const
{
logout
}
=
useAuth
();
const
{
logout
,
user
}
=
useAuth
();
const
[
search
,
setSearch
]
=
useState
(
""
);
const
[
search
,
setSearch
]
=
useState
(
""
);
const
handleChange
=
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
handleChange
=
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
...
@@ -33,7 +33,7 @@ export default function Header() {
...
@@ -33,7 +33,7 @@ export default function Header() {
</
div
>
</
div
>
</
div
>
</
div
>
<
div
className
=
"flex justify-end "
>
<
div
className
=
"flex justify-end "
>
{
useAuth
().
user
.
isLoggedIn
?
(
{
user
.
isLoggedIn
?
(
<
div
className
=
"flex text-xs"
>
<
div
className
=
"flex text-xs"
>
<
Link
to
=
"/profile"
className
=
"mr-2 "
>
<
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) => {
...
@@ -70,6 +70,7 @@ export const login = asyncWrap(async (req, res) => {
res
.
json
({
res
.
json
({
isLoggedIn
:
true
,
isLoggedIn
:
true
,
email
:
user
.
email
,
email
:
user
.
email
,
role
:
user
.
role
?.
name
,
});
});
});
});
...
...
src/db/user.db.ts
View file @
ed7b303c
import
bcrypt
from
"
bcryptjs
"
;
import
bcrypt
from
"
bcryptjs
"
;
import
{
ObjectId
}
from
"
mongoose
"
;
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
"
;
import
fs
from
"
fs/promises
"
;
export
const
createUser
=
async
(
user
:
IUser
)
=>
{
export
const
createUser
=
async
(
user
:
IUser
)
=>
{
// 비밀번호 암호화
// 비밀번호 암호화
const
hash
=
await
bcrypt
.
hash
(
user
.
password
,
10
);
const
hash
=
await
bcrypt
.
hash
(
user
.
password
,
10
);
const
newFileInfo
=
await
FileInfo
.
create
({});
//
const newFileInfo = await FileInfo.create({});
// 사용자 역할 추가: 기본값은 "user"
// 사용자 역할 추가: 기본값은 "user"
let
userRole
=
null
;
let
userRole
=
null
;
if
(
user
.
role
)
{
if
(
user
.
role
)
{
...
@@ -19,7 +19,7 @@ export const createUser = async (user: IUser) => {
...
@@ -19,7 +19,7 @@ export const createUser = async (user: IUser) => {
password
:
hash
,
password
:
hash
,
role
:
userRole
,
role
:
userRole
,
isNew
:
true
,
isNew
:
true
,
fileInfo
:
newFileInfo
.
_id
,
//
fileInfo: newFileInfo._id,
});
});
const
retUser
=
await
newUser
.
save
();
const
retUser
=
await
newUser
.
save
();
return
retUser
;
return
retUser
;
...
@@ -31,9 +31,11 @@ export const findUserByEmail = async (
...
@@ -31,9 +31,11 @@ export const findUserByEmail = async (
)
=>
{
)
=>
{
let
user
;
let
user
;
if
(
includePassword
)
{
if
(
includePassword
)
{
user
=
await
User
.
findOne
({
email
}).
select
(
"
+password
"
);
user
=
await
User
.
findOne
({
email
})
.
select
(
"
+password
"
)
.
populate
<
{
role
:
IRole
}
>
(
"
role
"
);
}
else
{
}
else
{
user
=
await
User
.
findOne
({
email
});
user
=
await
User
.
findOne
({
email
})
.
populate
<
{
role
:
IRole
}
>
(
"
role
"
)
;
}
}
return
user
;
return
user
;
};
};
...
...
src/models/index.ts
View file @
ed7b303c
export
{
default
as
User
,
IUser
}
from
"
./user.model
"
;
export
{
default
as
User
,
IUser
}
from
"
./user.model
"
;
export
{
default
as
Post
,
PostType
}
from
"
./post.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
FileInfo
,
IFileInfo
}
from
"
./fileinfo.model
"
;
export
{
default
as
Mainimg
,
MainimgType
}
from
"
./mainimg.model
"
;
export
{
default
as
Mainimg
,
MainimgType
}
from
"
./mainimg.model
"
;
src/models/role.model.ts
View file @
ed7b303c
import
{
model
,
Schema
}
from
"
mongoose
"
;
import
{
model
,
Schema
}
from
"
mongoose
"
;
interface
IRole
{
export
interface
IRole
{
name
:
string
;
name
:
string
;
priority
:
number
;
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
{
export
interface
IUser
{
email
:
string
;
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