Skip to content

Commit

Permalink
Merge pull request #22 from 42Seoul-LastDance/feature/auth
Browse files Browse the repository at this point in the history
Feature/auth
  • Loading branch information
Tolerblanc authored Sep 19, 2023
2 parents 69e8bac + 713a92b commit 8754841
Show file tree
Hide file tree
Showing 20 changed files with 553 additions and 335 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ all : $(NAME)

$(NAME) :
mkdir -p ./srcs/postgresql
@bash setting_ip.sh
@if docker info | grep -q "ERROR"; then \
echo "\033[0;96m--- Docker will be running soon ---"; \
echo "y" | ./utils/init_docker.sh; \
Expand Down Expand Up @@ -42,6 +43,6 @@ xtest :
docker exec next curl http://localhost:4242

exec :
docker exec -it react /bin/bash
docker exec -it next /bin/bash

.PHONY : all down clean fclean docker cntest stest xtest next
135 changes: 67 additions & 68 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,75 @@
version: "3"
version: '3'

services:
next:
container_name: next
build: ./services/next
image: next:ts
volumes:
- next:/usr/app/srcs
networks:
- my_network
env_file:
- ./.env
ports:
- "4242:3000"
restart: always
depends_on:
- postgresql
next:
container_name: next
build: ./services/next
image: next:ts
volumes:
- next:/usr/app/srcs
networks:
- my_network
env_file:
- ./.env
ports:
- '4242:4242'
restart: always
depends_on:
- postgresql

nest:
container_name: nest
build: ./services/nest
image: nest:ts
volumes:
- nest:/usr/app/srcs
networks:
- my_network
env_file:
- ./.env
ports:
- "3000:3000"
restart: always

postgresql:
container_name: postgresql
build:
context: ./services/postgresql
args:
- DB_NAME=${DB_NAME}
- POSTGRES_USER_ID=${POSTGRES_USER_ID}
- POSTGRES_USER_PASSWORD=${POSTGRES_USER_PASSWORD}
image: db:ts
expose:
- "5432"
volumes:
- db:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
networks:
- my_network
restart: always
nest:
container_name: nest
build: ./services/nest
image: nest:ts
volumes:
- nest:/usr/app/srcs
networks:
- my_network
env_file:
- ./.env
ports:
- '3000:3000'
restart: always

postgresql:
container_name: postgresql
build:
context: ./services/postgresql
args:
- DB_NAME=${DB_NAME}
- POSTGRES_USER_ID=${POSTGRES_USER_ID}
- POSTGRES_USER_PASSWORD=${POSTGRES_USER_PASSWORD}
image: db:ts
expose:
- '5432'
volumes:
- db:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
networks:
- my_network
restart: always

volumes:
next:
driver: local
driver_opts:
type: none
o: bind
device: '${PWD}/srcs/next'
nest:
driver: local
driver_opts:
type: none
o: bind
device: '${PWD}/srcs/nest'
db:
driver: local
driver_opts:
type: none
o: bind
device: '${PWD}/srcs/postgresql'
next:
driver: local
driver_opts:
type: none
o: bind
device: '${PWD}/srcs/next'
nest:
driver: local
driver_opts:
type: none
o: bind
device: '${PWD}/srcs/nest'
db:
driver: local
driver_opts:
type: none
o: bind
device: '${PWD}/srcs/postgresql'

networks:
my_network:
driver: bridge
my_network:
driver: bridge
1 change: 0 additions & 1 deletion services/nest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ COPY ./init_nest.sh /usr/app/
RUN apt-get update \
&& apt-get install -y dumb-init \
&& npm install -g npm \
&& npm install -g @nestjs/cli \
&& chmod 777 init_nest.sh


Expand Down
3 changes: 2 additions & 1 deletion services/nest/init_nest.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
npm install --prefix srcs --save @nestjs/cli
npm install --prefix srcs
npm run --prefix srcs start:dev
npm run --prefix srcs start:dev --cache-clear
11 changes: 11 additions & 0 deletions setting_ip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
line_address=$(grep -n "#local BACK Address" .env | cut -d: -f1)
if [ -z "$line_address" ]; then
IPADD="$(ifconfig | grep "inet 10." | awk '{print $2}')"
echo "" >> .env
echo "#local BACK Address" >> .env
echo "BACK_ADDR=http://$IPADD:3000" >> .env
echo "#local FRONT Address" >> .env
echo "FRONT_ADDR=http://$IPADD:4242" >> .env
echo "#local callback Address" >> .env
echo "FT_CALLBACK=http://$IPADD:3000/auth/callback" >> .env
fi
8 changes: 4 additions & 4 deletions srcs/nest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion srcs/nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"typeorm": "^0.3.17"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/cli": "^10.1.17",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
Expand Down
31 changes: 15 additions & 16 deletions srcs/nest/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<button id="codeSubmit">2fa verify</button><br />

<form
action="http://10.14.9.3:3000/users/signupUser"
action="http://10.14.3.1:3000/users/signup"
method="POST"
enctype="multipart/form-data"
>
Expand All @@ -47,10 +47,10 @@
required
/>
<br />
<!-- <label for="username">유저 이름:</label>
<input type="text" name="username" id="username" required>
<br>
<label for="require2fa">2FA 필요 여부:</label>
<label for="username">유저 이름:</label>
<input type="text" name="username" id="username" required />
<br />
<!-- <label for="require2fa">2FA 필요 여부:</label>
<input type="checkbox" name="require2fa" id="require2fa">
<br> -->
<input type="submit" value="이미지 파일 업로드" />
Expand Down Expand Up @@ -101,7 +101,7 @@
};
try {
const response = await fetch(
'http://10.14.9.3:3000/auth/login',
'http://10.14.3.1:3000/auth/login',
requestOptions,
);
if (!response.ok) {
Expand All @@ -127,7 +127,7 @@
headers: headers,
};
const response = await fetch(
'http://10.14.9.3:3000/auth/require2fa',
'http://10.14.3.1:3000/auth/require2fa',
requestOptions,
);
const data = await response.json();
Expand Down Expand Up @@ -156,7 +156,7 @@
headers: headers,
};
const response = await fetch(
'http://10.14.9.3:3000/auth/logout',
'http://10.14.3.1:3000/auth/logout',
requestOptions,
);
if (!response.ok) {
Expand All @@ -178,7 +178,7 @@
headers: headers,
};
const response = await fetch(
'http://10.14.9.3:3000/auth/regenerateToken',
'http://10.14.3.1:3000/auth/regenerateToken',
);
if (!response.ok) {
if (response.status == 401) alert('refresh => 42login');
Expand All @@ -189,7 +189,7 @@
}

async function login42() {
window.location.href = 'http://10.14.9.3:3000/auth/42login';
window.location.href = 'http://10.14.3.1:3000/auth/42login';
}

const checkLogin = document.getElementById('loginButton');
Expand Down Expand Up @@ -225,16 +225,15 @@
async function enroll() {
const imageInput = document.getElementById('image');
// const genderInputs = document.getElementsByName('2faa');
// const nameInput = document.getElementById('username');
const nameInput = document.getElementById('username');

// // 사용자 입력 가져오기
const imageFile = imageInput.files[0];
// const selectedGender = [...genderInputs].find(
// (input) => input.checked,
// ).value;
// const enteredName = nameInput.value;
const enteredName = nameInput.value;

const access_token = getCookie('temp_token');
const headers = {
Authorization: `Bearer ${access_token}`, // access_token을 Bearer 토큰으로 사용
'Content-Type': 'application/json', // 요청 데이터가 JSON 형식인 경우
Expand All @@ -243,13 +242,13 @@
const bodies = {
image_url: imageFile,
// require2fa: false,
// username: enteredName,
username: enteredName,
};

// 서버로 데이터 전송
try {
const response = await fetch(
'http://10.14.9.3:3000/users/signupUser',
'http://10.14.3.1:3000/users/signup',
{
method: 'POST',
headers: headers,
Expand Down Expand Up @@ -294,7 +293,7 @@
headers: headers,
};
const response = await fetch(
`http://10.14.9.3:3000/auth/verify2fa?code=${inputField}`,
`http://10.14.3.1:3000/auth/verify2fa?code=${inputField}`,
requestOptions,
);

Expand Down
Loading

0 comments on commit 8754841

Please sign in to comment.