diff --git a/app.js b/app.js
index 59c8edd92..4c4ba875d 100644
--- a/app.js
+++ b/app.js
@@ -42,7 +42,6 @@ exports.init = async ( ) => {
}
if ( process.env.COMPRESSION ) {
- debug( `speckle:startup` )( 'Using app level compression. Consider enabling this at a proxy level.' )
app.use( compression( ) )
}
@@ -77,7 +76,9 @@ exports.init = async ( ) => {
plugins: [
require( `${appRoot}/logging/apolloPlugin` )
],
- tracing: process.env.NODE_ENV === 'development'
+ tracing: process.env.NODE_ENV === 'development',
+ introspection: true,
+ playground: true
} )
graphqlServer.applyMiddleware( { app: app } )
@@ -106,8 +107,7 @@ exports.startHttp = async ( app ) => {
debug( 'speckle:http-startup' )( '⨠Proxying frontend (dev mode):' )
debug( 'speckle:http-startup' )( `đ main application: http://localhost:${port}/` )
- debug( 'speckle:http-startup' )( `đ auth application: http://localhost:${port}/auth` )
- debug( 'speckle:hint' )( ` âšī¸ Don't forget to run "npm run dev:frontend" in a different terminal to start the vue application.` )
+ debug( 'speckle:hint' )( 'âšī¸ Don\'t forget to run "npm run dev:frontend" in a different terminal to start the vue application.' )
}
// Production mode -> serve things statically.
@@ -136,7 +136,7 @@ exports.startHttp = async ( app ) => {
app.use( Sentry.Handlers.errorHandler( ) )
server.on( 'listening', ( ) => {
- debug( `speckle:startup` )( ` đ My name is Spockle Server, and I'm running at ${server.address().port}` )
+ debug( 'speckle:startup' )( ` đ My name is Spockle Server, and I'm running at ${server.address().port}` )
} )
server.listen( port )
diff --git a/frontend/src/auth-helpers.js b/frontend/src/auth-helpers.js
index b7c320a61..2eb40c6ae 100644
--- a/frontend/src/auth-helpers.js
+++ b/frontend/src/auth-helpers.js
@@ -13,7 +13,6 @@ export async function checkAccessCodeAndGetTokens() {
let response = await getTokenFromAccessCode(accessCode)
// eslint-disable-next-line no-prototype-builtins
if (response.hasOwnProperty('token')) {
- localStorage.clear()
localStorage.setItem('AuthToken', response.token)
localStorage.setItem('RefreshToken', response.refreshToken)
window.history.replaceState({}, document.title, '/')
@@ -68,14 +67,6 @@ export async function getTokenFromAccessCode(accessCode) {
return data
}
-export function redirectToAuth() {
- // Reaching this stage means we're initialising a full new auth flow,
- // TIP: also means we need to refresh the app challenge as well.
- localStorage.setItem('appChallenge', crs({ length: 10 }))
- // Finally, redirect to the auth lock.
- window.location = `/auth?appId=${appId}&challenge=${localStorage.getItem('appChallenge')}`
-}
-
/**
* Signs out the current session
* @return {null}
diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js
index 6d8322d07..70da9c5e1 100644
--- a/frontend/src/router/index.js
+++ b/frontend/src/router/index.js
@@ -161,38 +161,23 @@ const router = new VueRouter({
router.beforeEach((to, from, next) => {
let uuid = localStorage.getItem('uuid')
let redirect = localStorage.getItem('shouldRedirectTo')
- let path = to.path
- let name = to.name
- console.log(uuid, redirect, path, name)
+ if (!uuid && to.name !== 'Login' && to.name !== 'Register') {
+ localStorage.setItem('shouldRedirectTo', to.path)
- if (!uuid && (to.name !== 'Login' && to.name !== 'Register')) return next({ name: 'Login' })
+ return next({ name: 'Login' })
+ }
+
+ if ((to.name === 'Login' || to.name === 'Register') && uuid) {
+ return next({ name: 'home' })
+ }
+
+ if (uuid && redirect && redirect !== to.path) {
+ localStorage.removeItem('shouldRedirectTo')
+ return next({ path: redirect })
+ }
return next()
- // if (!(to.name === 'Login' || to.name === 'Register') && !localStorage.getItem('uuid')) {
- // localStorage.setItem('shouldRedirectTo', to.path)
- // return next({ name: 'Login' })
- // } else if (
- // (to.name === 'Login' || to.name === 'Register') &&
- // !!localStorage.getItem('uuid') &&
- // !!localStorage.getItem('shouldRedirectTo')
- // ) {
- // return next({ name: 'home' })
- // } else if (localStorage.getItem('shouldRedirectTo')) {
- // let path = localStorage.getItem('shouldRedirectTo')
- // localStorage.removeItem('shouldRedirectTo')
- // return next({ path })
- // } else {
- // return next()
- // }
-
- // else if (localStorage.getItem('uuid')) {
- // let shouldRedirectTo = localStorage.getItem('shouldRedirectTo')
- // localStorage.removeItem('shouldRedirectTo')
- // if (shouldRedirectTo) {
- // return next() // TODO: redirect to prev url
- // } else return next()
- // }
})
//TODO: include stream name in page title eg `My Cool Stream | Speckle`
diff --git a/modules/apiexplorer/explorer.html b/modules/apiexplorer/explorer.html
index e100e6126..e856ef3f0 100644
--- a/modules/apiexplorer/explorer.html
+++ b/modules/apiexplorer/explorer.html
@@ -25,127 +25,127 @@
+
+ let data = await response.json( )
+
+ if ( data.hasOwnProperty( 'token' ) ) {
+ localStorage.removeItem( 'challenge' )
+ localStorage.setItem( 'AuthToken', data.token )
+ localStorage.setItem( 'RefreshToken', data.refreshToken )
+ await setUserName( )
+ await initGQL( data.token )
+ }
+
+}
+
+async function initGQL( token ) {
+ // GraphQLPlayground.init( document.getElementById( 'root' ), {
+ // endpointUrl: '/graphql',
+ // headers: {
+ // 'Authorization': 'Bearer ' + token
+ // }
+ // } )
+ ReactDOM.render(
+ React.createElement( GraphiQL, { fetcher: graphQLFetcher } ),
+ document.getElementById( 'graphiql' ),
+ )
+ await setServerInfo( )
+}
+
+async function setUserName( ) {
+ let testResponse = await fetch( '/graphql', {
+ method: 'POST',
+ headers: {
+ 'Authorization': 'Bearer ' + localStorage.getItem( 'AuthToken' ),
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify( { query: `{ user { name } }` } )
+ } )
+
+ let data = ( await testResponse.json( ) ).data
+ document.getElementById( 'username' ).innerHTML = data.user.name
+}
+
+async function setServerInfo( ) {
+ let testResponse = await fetch( '/graphql', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify( { query: `{ serverInfo { name company } }` } )
+ } )
+
+ let data = ( await testResponse.json( ) ).data
+ document.getElementById( 'serverDetails' ).innerHTML = `${data.serverInfo.name} deployed by ${data.serverInfo.company}`
+}
+
+function logout( ) {
+ localStorage.removeItem( 'AuthToken' )
+ localStorage.removeItem( 'RefreshToken' )
+ window.location = '/explorer'
+}
+
+window.addEventListener( 'load', async function ( event ) {
+ let urlParams = new URLSearchParams( window.location.search )
+ let accessCode = urlParams.get( 'access_code' )
+
+ if ( accessCode ) {
+ accessCodeExchange( accessCode )
+ } else {
+ let token = localStorage.getItem( 'AuthToken' )
+ if ( token ) {
+ let testResponse = await fetch( '/graphql', {
+ method: 'POST',
+ headers: {
+ 'Authorization': 'Bearer ' + token,
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify( { query: '{ user { name } }' } )
+ } )
+
+ let data = ( await testResponse.json( ) ).data
+ // if res.data.user is non null, means the ping was ok & token is valid
+ if ( data.user ) {
+ console.log( data.user )
+ document.getElementById( 'username' ).innerHTML = data.user.name
+ await initGQL( token )
+
+ }
+ } else {
+ redirectToAuth( )
+ }
+ }
+} )
+