Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Commit c9405fa

Browse files
authored
Merge pull request #8 from hisasann/feature/add-login-logout-logincheck
Feature/add login logout logincheck
2 parents 5cfee8a + 255e49f commit c9405fa

File tree

27 files changed

+445
-102
lines changed

27 files changed

+445
-102
lines changed

nuxt.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ module.exports = {
128128
}
129129
},
130130
router: {
131-
middleware: 'check-auth',
131+
// リロードのタイミングでは SSR 側で実行される
132+
// ルーティングの度に CSR 側で実行される
133+
// ログインの必要のない画面でも middleware が実行されるので注意が必要
134+
// middleware: 'check-auth',
132135

133136
extendRoutes(routes: any, resolve: any) {
134137
// https://ja.nuxtjs.org/api/configuration-router/#extendroutes
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
1+
import { AxiosInstance, AxiosRequestConfig, AxiosError } from 'axios'
12
import Vue from 'vue'
23

4+
interface NuxtAxiosInstance extends AxiosInstance {
5+
// * Methods
6+
$request<T = any>(config: AxiosRequestConfig): Promise<T>
7+
$get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>
8+
$delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>
9+
$head<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>
10+
$options<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>
11+
$post<T = any>(
12+
url: string,
13+
data?: any,
14+
config?: AxiosRequestConfig
15+
): Promise<T>
16+
$put<T = any>(
17+
url: string,
18+
data?: any,
19+
config?: AxiosRequestConfig
20+
): Promise<T>
21+
$patch<T = any>(
22+
url: string,
23+
data?: any,
24+
config?: AxiosRequestConfig
25+
): Promise<T>
26+
// * Helpers
27+
onRequest(fn: (config: AxiosRequestConfig) => void): void
28+
onResponse<T = any>(fn: (response: T) => void): void
29+
onError(fn: (error: AxiosError) => void): void
30+
onRequestError(fn: (error: AxiosError) => void): void
31+
onResponseError(fn: (error: AxiosError) => void): void
32+
setHeader(name: string, value: any, scopes?: string | string[]): void
33+
setToken(token: string, type: string, scopes?: string | string[]): void
34+
}
35+
336
declare module 'vue/types/vue' {
437
interface Vue {
5-
$axios: any
38+
$axios: NuxtAxiosInstance
639
}
740
}

src/common/constants/api.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Env from '@/common/env/'
2+
3+
const getBffUrl = (path: string): string => [Env.url, path].join('')
4+
5+
export const API_ENDPOINT = {
6+
/** ログイン状態チェック */
7+
LOGIN_CHECK: getBffUrl('/login-check'),
8+
/** ログイン */
9+
LOGIN: getBffUrl('/login'),
10+
/** ログアウト */
11+
LOGOUT: getBffUrl('/logout')
12+
}

src/common/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ console.log('process.env.NODE_ENV: ', process.env.NODE_ENV)
66
console.log('RUNTIME_ENV: ', process.env.RUNTIME_ENV)
77

88
export * from './pjName'
9+
export * from './api'

src/common/env/env.dev.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Env = {
2-
envName: 'dev'
2+
envName: 'dev',
3+
url: 'http://localhost:5000'
34
}
45

56
export default Env

src/common/env/env.prod.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Env = {
2-
envName: 'prod'
2+
envName: 'prod',
3+
url: 'http://localhost:5000'
34
}
45

56
export default Env

src/common/env/env.stg.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Env = {
2-
envName: 'stg'
2+
envName: 'stg',
3+
url: 'http://localhost:5000'
34
}
45

56
export default Env

src/common/env/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import EnvDev from './env.dev'
22
import EnvStg from './env.stg'
33
import EnvProd from './env.prod'
4-
import { EnvInterface } from '@/interface/EnvInterface'
4+
import { IEnv } from '@/interface/IEnv'
55

66
console.log('process.env.NODE_ENV: ', process.env.NODE_ENV)
77

8-
let Env: EnvInterface
8+
let Env: IEnv
99
if (process.env.NODE_ENV === 'production') {
1010
Env = EnvProd
1111
} else if (process.env.NODE_ENV === 'staging') {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Api Payload インターフェイス
33
*/
4-
export interface ApiPayloadInterface {
4+
export interface IApiPayload {
55
hoge: string
66
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* Env インターフェイス
33
*/
4-
export interface EnvInterface {
4+
export interface IEnv {
55
envName: string
6+
url: string
67
}

0 commit comments

Comments
 (0)