generated from ooooorobo/react-mobile-web-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from wanted-fork-fork/release/v0.1.1--proect-s…
…etting [Release] v0.1.1 - 프로젝트 세팅
- Loading branch information
Showing
15 changed files
with
265 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
/** @type {import('next').NextConfig} */ | ||
module.exports = { | ||
reactStrictMode: true, | ||
env: { | ||
BASE_URL: | ||
process.env.BASE_URL || | ||
"https://ec2-13-124-94-121.ap-northeast-2.compute.amazonaws.com:8080", | ||
IS_DEV: process.env.NODE_ENV === "development", | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const API_PREFIX = { | ||
AUTH: "/auth", | ||
}; | ||
|
||
export default { | ||
API_PREFIX, | ||
}; |
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,13 @@ | ||
import axios from "axios"; | ||
import { Agent } from "https"; | ||
|
||
function createAxiosInstance() { | ||
return axios.create({ | ||
httpsAgent: new Agent({ | ||
rejectUnauthorized: false, | ||
}), | ||
withCredentials: true, | ||
}); | ||
} | ||
|
||
export default { createAxiosInstance }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface LoginDto { | ||
email: string; | ||
pwd: string; | ||
} |
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,13 @@ | ||
import { LoginDto } from "@src/models/dto/user.dto"; | ||
|
||
function buildLoginDto({ | ||
email, | ||
password, | ||
}: { | ||
email: string; | ||
password: string; | ||
}): LoginDto { | ||
return { email, pwd: password }; | ||
} | ||
|
||
export default { buildLoginDto }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
import BaseHttpService from "@src/services/BaseHttp.service"; | ||
import Router from "next/router"; | ||
import { LoginDto } from "@src/models/dto/user.dto"; | ||
import { API_PREFIX } from "@src/constant/api.constant"; | ||
|
||
export default class AuthService extends BaseHttpService { | ||
async login(): Promise<boolean> { | ||
return Router.push(`${this.BASE_URL}/`); | ||
prefix = API_PREFIX.AUTH; | ||
|
||
async login(loginDto: LoginDto): Promise<string> { | ||
return (await this.post<string>( | ||
`${this.prefix}/login`, | ||
loginDto, | ||
)) as string; | ||
} | ||
|
||
logout() { | ||
this.removeToken(); | ||
} | ||
|
||
async test(): Promise<string> { | ||
return (await this.get<string>(`/test`)) as string; | ||
} | ||
|
||
async refresh(): Promise<string> { | ||
return (await this.post<string>(`${this.prefix}/refresh`)) as string; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { makeAutoObservable } from "mobx"; | ||
|
||
// store | ||
import { RootStore } from "@src/store/root.store"; | ||
import AuthService from "@src/services/Auth.service"; | ||
|
||
// model | ||
import { LoginDto } from "@src/models/dto/user.dto"; | ||
import UserMapper from "@src/models/mapper/user.mapper"; | ||
|
||
export default class UserStore { | ||
private readonly rootStore: RootStore; | ||
|
||
private readonly authService: AuthService; | ||
|
||
constructor(rootStore: RootStore, authService: AuthService) { | ||
this.authService = authService; | ||
this.rootStore = rootStore; | ||
|
||
makeAutoObservable(this); | ||
} | ||
|
||
async login({ email, password }) { | ||
const loginDto: LoginDto = UserMapper.buildLoginDto({ email, password }); | ||
const token = await this.authService.login(loginDto); | ||
this.authService._saveToken(token); | ||
} | ||
|
||
async test() { | ||
await this.authService.test(); | ||
} | ||
|
||
async refresh() { | ||
const token = await this.authService.refresh(); | ||
this.authService._saveToken(token); | ||
} | ||
} |
Oops, something went wrong.