Tweaks to login flow (#1)

This commit is contained in:
Daniel J. Summers 2020-11-23 21:33:37 -05:00
parent 6d16bef137
commit daece3eab1
3 changed files with 24 additions and 8 deletions

View File

@ -40,7 +40,7 @@ export function authorize() {
* *
* @param authCode The authorization code obtained from No Agenda Social * @param authCode The authorization code obtained from No Agenda Social
*/ */
export async function logOn(authCode: string) { export async function logOn(authCode: string): Promise<string> {
try { try {
const resp = await doRequest(`${NAS_URL}oauth/token`, 'POST', const resp = await doRequest(`${NAS_URL}oauth/token`, 'POST',
JSON.stringify({ JSON.stringify({
@ -54,10 +54,8 @@ export async function logOn(authCode: string) {
) )
const token = await resp.json() const token = await resp.json()
await jjjAuthorize(token.access_token) await jjjAuthorize(token.access_token)
// TODO: navigate to user welcome page return ''
console.info(`Success - response ${JSON.stringify(token)}`)
} catch (e) { } catch (e) {
// TODO: notify the user return `${e}`
console.error(`Failure - ${e}`)
} }
} }

View File

@ -1,6 +1,7 @@
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router' import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Home from '../views/Home.vue' import Home from '../views/Home.vue'
import Welcome from '../views/citizen/Welcome.vue'
import Authorized from '../views/user/Authorized.vue' import Authorized from '../views/user/Authorized.vue'
const routes: Array<RouteRecordRaw> = [ const routes: Array<RouteRecordRaw> = [
@ -22,6 +23,11 @@ const routes: Array<RouteRecordRaw> = [
name: 'Authorized', name: 'Authorized',
component: Authorized, component: Authorized,
props: (route) => ({ code: route.query.code }) props: (route) => ({ code: route.query.code })
},
{
path: '/citizen/welcome',
name: 'Welcome',
component: Welcome
} }
] ]

View File

@ -1,8 +1,9 @@
<template> <template>
<p>Logging you on with No Agenda Social...</p> <p>{{message}}</p>
</template> </template>
<script lang="ts"> <script lang="ts">
import { ref } from 'vue'
import { logOn } from '@/auth' import { logOn } from '@/auth'
export default { export default {
@ -11,8 +12,19 @@ export default {
type: String type: String
} }
}, },
setup(props) { setup() {
logOn(props.code) const message = ref('Logging you on with No Agenda Social...')
return {
message
}
},
async mounted() {
const result = await logOn(this.code)
if (result === '') {
this.$router.push('/citizen/welcome')
} else {
this.message = `Unable to log on via No Agenda Social:\n${result}`
}
} }
} }
</script> </script>