Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Commit

Permalink
OAuth endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dyakovri committed Feb 17, 2023
1 parent 9833d55 commit 88aca44
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 132 deletions.
3 changes: 1 addition & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ VUE_APP_API_REPORT=https://report.api.test.profcomff.com
VUE_APP_API_TIMETABLE=https://timetable.api.test.profcomff.com
VUE_APP_API_NAVBAR=https://navbar.api.test.profcomff.com
VUE_APP_API_MARKETING=https://marketing.api.test.profcomff.com
VUE_APP_FEEDBACK_FORM=https://forms.yandex.ru/u/635d013b068ff0587320bfc9/

VUE_APP_API_AUTH=https://auth.api.test.profcomff.com
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ VUE_APP_API_REPORT=https://report.api.profcomff.com
VUE_APP_API_TIMETABLE=https://timetable.api.profcomff.com
VUE_APP_API_NAVBAR=https://navbar.api.profcomff.com
VUE_APP_API_MARKETING=https://marketing.api.profcomff.com
VUE_APP_API_AUTH=https://auth.api.profcomff.com
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@profcomff/auth",
"name": "@profcomff/auth-webapp",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"start": "vue-cli-service serve --port 9006",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"serve:standalone": "vue-cli-service serve --mode standalone"
Expand Down
28 changes: 3 additions & 25 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@

<template>
<img alt="Vue logo" :src="url">
<HelloWorld msg="Ура! Вы создали приложение для Твой ФФ!"/>
<RouterView />
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'App',
components: {
HelloWorld
},
data: () => ({
url: `${process.env.VUE_APP_CDN}/app/logo/logo_ff.svg`
})
}
export default {};
</script>

<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>

<style></style>
59 changes: 0 additions & 59 deletions src/components/HelloWorld.vue

This file was deleted.

84 changes: 64 additions & 20 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,69 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { createRouter, createWebHistory } from 'vue-router';

const routes = [
{
path: '/',
name: 'home',
component: HomeView
},
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
}
]
{
path: '/auth',
component: () => import('../views/AuthView.vue'),
},
{
path: '/auth/register',
component: () => import('../views/RegisterView.vue'),
},
{
path: '/auth/reset_password',
component: () => import('../views/ResetPwdView.vue'),
},
{
path: '/auth/oauth-authorized/:oauthProvider',
component: () => {},
meta: { oauthProvider: true },
},
{
path: '/user',
component: () => import('../views/UserView.vue'),
meta: { userNeededScopes: [] },
},
];

const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
history: createWebHistory(process.env.BASE_URL),
routes,
});

export default router
router.beforeEach(async (to, from) => {
// Log to marketing API
fetch(`${process.env.VUE_APP_API_MARKETING}/action`, {
method: 'POST',
cache: 'no-cache',
redirect: 'follow',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
user_id: localStorage.getItem('marketing-id'),
action: 'route to',
path_from: from.fullPath || null,
path_to: to.fullPath || null,
}),
}).catch();

if (to.meta.oauthProvider) {
console.log(to.query);
try {
let resp = await fetch(
`${process.env.VUE_APP_API_AUTH}/${to.params.oauthProvider}/login`,
{
method: 'POST',
cache: 'no-cache',
redirect: 'follow',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(to.query),
},
).json();
if (resp.token) return { path: '/user' };
else return { path: '/auth' };
} catch (error) {
return { path: '/auth' };
}
}
});

export default router;
5 changes: 0 additions & 5 deletions src/views/AboutView.vue

This file was deleted.

9 changes: 9 additions & 0 deletions src/views/AuthView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<p>Auth</p>
</template>

<script>
export default {};
</script>

<style></style>
18 changes: 0 additions & 18 deletions src/views/HomeView.vue

This file was deleted.

9 changes: 9 additions & 0 deletions src/views/RegisterView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<p>register</p>
</template>

<script>
export default {};
</script>

<style></style>
9 changes: 9 additions & 0 deletions src/views/ResetPwdView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<p>reset</p>
</template>

<script>
export default {};
</script>

<style></style>
9 changes: 9 additions & 0 deletions src/views/UserView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<p>user</p>
</template>

<script>
export default {};
</script>

<style></style>

0 comments on commit 88aca44

Please sign in to comment.