Skip to content

Commit

Permalink
feat(web): intergate login with api
Browse files Browse the repository at this point in the history
  • Loading branch information
Hagith committed Feb 8, 2020
1 parent 19b79ef commit 6159748
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
4 changes: 4 additions & 0 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

// TODO configure allowed origins
app.enableCors();

const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT || 3000;
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/modules/auth/domain/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { InitializerTask } from '~app/core';
import store from '~app/core/store';
import { authActions } from '../store';

// TODO shared DTO
export interface AuthToken {
access: string;
refresh: string;
Expand Down
20 changes: 7 additions & 13 deletions apps/web/src/modules/auth/store/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axios from 'axios';
import { RootState } from '~app/core/store';
import { createActionFactory } from '~app/shared/store';
import { AuthToken, loadStoredToken } from '../domain/token';
Expand All @@ -21,19 +22,12 @@ export const actions = {
return;
}

// TODO API service
return new Promise((resolve, reject) =>
setTimeout(() => {
if (login === 'admin@example.com' && password === 'password') {
const res: AuthToken = { access: 'access_token', refresh: 'refresh_token' };

commit(authMutations.setToken, res, { root: true });
resolve(res);
} else {
reject();
}
}, 500),
);
return axios
.post<AuthToken>('/auth', {
login,
password,
})
.then(res => commit(authMutations.setToken, res.data, { root: true }));
}),

logout: createAction(({ commit }) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/modules/auth/views/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<input
name="login"
class="form-control"
type="email"
placeholder="Email"
type="text"
placeholder="Login"
v-model="form.login"
/>
</div>
Expand Down

0 comments on commit 6159748

Please sign in to comment.