├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .postcssrc.js ├── README.md ├── build ├── build.js ├── check-versions.js ├── dev-client.js ├── dev-server.js ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js └── webpack.prod.conf.js ├── config ├── dev.env.js ├── index.js └── prod.env.js ├── index.html ├── package.json ├── server ├── package.json └── server.js ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ ├── AppNav.vue │ ├── callback.vue │ ├── privateBattles.vue │ └── publicBattles.vue ├── main.js └── router │ └── index.js ├── static └── .gitkeep ├── utils ├── auth.js └── battles-api.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { "modules": false }], 4 | "stage-2" 5 | ], 6 | "plugins": ["transform-runtime"], 7 | "comments": false, 8 | "env": { 9 | "test": { 10 | "presets": ["env", "stage-2"], 11 | "plugins": [ "istanbul" ] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build/*.js 2 | config/*.js 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // http://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | }, 12 | extends: 'airbnb-base', 13 | // required to lint *.vue files 14 | plugins: [ 15 | 'html' 16 | ], 17 | // check if imports actually resolve 18 | 'settings': { 19 | 'import/resolver': { 20 | 'webpack': { 21 | 'config': 'build/webpack.base.conf.js' 22 | } 23 | } 24 | }, 25 | // add your custom rules here 26 | 'rules': { 27 | // don't require .vue extension when importing 28 | 'import/extensions': ['error', 'always', { 29 | 'js': 'never', 30 | 'vue': 'never' 31 | }], 32 | // allow optionalDependencies 33 | 'import/no-extraneous-dependencies': ['error', { 34 | 'optionalDependencies': ['test/unit/index.js'] 35 | }], 36 | // allow debugger during development 37 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserlist" field in package.json 6 | "autoprefixer": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Vuejs 2 Authentication Tutorial 2 | 3 | This is the code that accompanies the **[Vuejs 2 Authentication Tutorial](https://auth0.com/blog/vuejs2-authentication-tutorial/)** on *[Auth0 Blog](https://auth0.com/blog/)* 4 | 5 | ![Lock Login Widget](https://cdn2.auth0.com/blog/startupbattle/login.png) 6 | _Lock Login Widget_ 7 | 8 | ![User consent dialog](https://cdn2.auth0.com/blog/startupbattle/authorize.png) 9 | _User presented with an option to authorize_ 10 | 11 | ## Installation 12 | 13 | ```bash 14 | 15 | # Get the project 16 | git clone git@github.com:auth0-blog/vuejs2-authentication-tutorial.git vuejs2-authentication-tutorial 17 | 18 | 19 | # Change directory 20 | cd vuejs2-authentication-tutorial 21 | 22 | # Install the dependencies 23 | npm install 24 | 25 | # Run your app 26 | npm run dev 27 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | process.env.NODE_ENV = 'production' 4 | 5 | var ora = require('ora') 6 | var rm = require('rimraf') 7 | var path = require('path') 8 | var chalk = require('chalk') 9 | var webpack = require('webpack') 10 | var config = require('../config') 11 | var webpackConfig = require('./webpack.prod.conf') 12 | 13 | var spinner = ora('building for production...') 14 | spinner.start() 15 | 16 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 17 | if (err) throw err 18 | webpack(webpackConfig, function (err, stats) { 19 | spinner.stop() 20 | if (err) throw err 21 | process.stdout.write(stats.toString({ 22 | colors: true, 23 | modules: false, 24 | children: false, 25 | chunks: false, 26 | chunkModules: false 27 | }) + '\n\n') 28 | 29 | console.log(chalk.cyan(' Build complete.\n')) 30 | console.log(chalk.yellow( 31 | ' Tip: built files are meant to be served over an HTTP server.\n' + 32 | ' Opening index.html over file:// won\'t work.\n' 33 | )) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 1 | var chalk = require('chalk') 2 | var semver = require('semver') 3 | var packageConfig = require('../package.json') 4 | 5 | function exec (cmd) { 6 | return require('child_process').execSync(cmd).toString().trim() 7 | } 8 | 9 | var versionRequirements = [ 10 | { 11 | name: 'node', 12 | currentVersion: semver.clean(process.version), 13 | versionRequirement: packageConfig.engines.node 14 | }, 15 | { 16 | name: 'npm', 17 | currentVersion: exec('npm --version'), 18 | versionRequirement: packageConfig.engines.npm 19 | } 20 | ] 21 | 22 | module.exports = function () { 23 | var warnings = [] 24 | for (var i = 0; i < versionRequirements.length; i++) { 25 | var mod = versionRequirements[i] 26 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 27 | warnings.push(mod.name + ': ' + 28 | chalk.red(mod.currentVersion) + ' should be ' + 29 | chalk.green(mod.versionRequirement) 30 | ) 31 | } 32 | } 33 | 34 | if (warnings.length) { 35 | console.log('') 36 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 37 | console.log() 38 | for (var i = 0; i < warnings.length; i++) { 39 | var warning = warnings[i] 40 | console.log(' ' + warning) 41 | } 42 | console.log() 43 | process.exit(1) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /build/dev-client.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | require('eventsource-polyfill') 3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 4 | 5 | hotClient.subscribe(function (event) { 6 | if (event.action === 'reload') { 7 | window.location.reload() 8 | } 9 | }) 10 | -------------------------------------------------------------------------------- /build/dev-server.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | var config = require('../config') 4 | if (!process.env.NODE_ENV) { 5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 6 | } 7 | 8 | var opn = require('opn') 9 | var path = require('path') 10 | var express = require('express') 11 | var webpack = require('webpack') 12 | var proxyMiddleware = require('http-proxy-middleware') 13 | var webpackConfig = require('./webpack.dev.conf') 14 | 15 | // default port where dev server listens for incoming traffic 16 | var port = process.env.PORT || config.dev.port 17 | // automatically open browser, if not set will be false 18 | var autoOpenBrowser = !!config.dev.autoOpenBrowser 19 | // Define HTTP proxies to your custom API backend 20 | // https://github.com/chimurai/http-proxy-middleware 21 | var proxyTable = config.dev.proxyTable 22 | 23 | var app = express() 24 | var compiler = webpack(webpackConfig) 25 | 26 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 27 | publicPath: webpackConfig.output.publicPath, 28 | quiet: true 29 | }) 30 | 31 | var hotMiddleware = require('webpack-hot-middleware')(compiler, { 32 | log: () => {} 33 | }) 34 | // force page reload when html-webpack-plugin template changes 35 | compiler.plugin('compilation', function (compilation) { 36 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 37 | hotMiddleware.publish({ action: 'reload' }) 38 | cb() 39 | }) 40 | }) 41 | 42 | // proxy api requests 43 | Object.keys(proxyTable).forEach(function (context) { 44 | var options = proxyTable[context] 45 | if (typeof options === 'string') { 46 | options = { target: options } 47 | } 48 | app.use(proxyMiddleware(options.filter || context, options)) 49 | }) 50 | 51 | // handle fallback for HTML5 history API 52 | app.use(require('connect-history-api-fallback')()) 53 | 54 | // serve webpack bundle output 55 | app.use(devMiddleware) 56 | 57 | // enable hot-reload and state-preserving 58 | // compilation error display 59 | app.use(hotMiddleware) 60 | 61 | // serve pure static assets 62 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 63 | app.use(staticPath, express.static('./static')) 64 | 65 | var uri = 'http://localhost:' + port 66 | 67 | var _resolve 68 | var readyPromise = new Promise(resolve => { 69 | _resolve = resolve 70 | }) 71 | 72 | console.log('> Starting dev server...') 73 | devMiddleware.waitUntilValid(() => { 74 | console.log('> Listening at ' + uri + '\n') 75 | // when env is testing, don't need open it 76 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 77 | opn(uri) 78 | } 79 | _resolve() 80 | }) 81 | 82 | var server = app.listen(port) 83 | 84 | module.exports = { 85 | ready: readyPromise, 86 | close: () => { 87 | server.close() 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 4 | 5 | exports.assetsPath = function (_path) { 6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' 7 | ? config.build.assetsSubDirectory 8 | : config.dev.assetsSubDirectory 9 | return path.posix.join(assetsSubDirectory, _path) 10 | } 11 | 12 | exports.cssLoaders = function (options) { 13 | options = options || {} 14 | 15 | var cssLoader = { 16 | loader: 'css-loader', 17 | options: { 18 | minimize: process.env.NODE_ENV === 'production', 19 | sourceMap: options.sourceMap 20 | } 21 | } 22 | 23 | // generate loader string to be used with extract text plugin 24 | function generateLoaders (loader, loaderOptions) { 25 | var loaders = [cssLoader] 26 | if (loader) { 27 | loaders.push({ 28 | loader: loader + '-loader', 29 | options: Object.assign({}, loaderOptions, { 30 | sourceMap: options.sourceMap 31 | }) 32 | }) 33 | } 34 | 35 | // Extract CSS when that option is specified 36 | // (which is the case during production build) 37 | if (options.extract) { 38 | return ExtractTextPlugin.extract({ 39 | use: loaders, 40 | fallback: 'vue-style-loader' 41 | }) 42 | } else { 43 | return ['vue-style-loader'].concat(loaders) 44 | } 45 | } 46 | 47 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 48 | return { 49 | css: generateLoaders(), 50 | postcss: generateLoaders(), 51 | less: generateLoaders('less'), 52 | sass: generateLoaders('sass', { indentedSyntax: true }), 53 | scss: generateLoaders('sass'), 54 | stylus: generateLoaders('stylus'), 55 | styl: generateLoaders('stylus') 56 | } 57 | } 58 | 59 | // Generate loaders for standalone style files (outside of .vue) 60 | exports.styleLoaders = function (options) { 61 | var output = [] 62 | var loaders = exports.cssLoaders(options) 63 | for (var extension in loaders) { 64 | var loader = loaders[extension] 65 | output.push({ 66 | test: new RegExp('\\.' + extension + '$'), 67 | use: loader 68 | }) 69 | } 70 | return output 71 | } 72 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var config = require('../config') 3 | var isProduction = process.env.NODE_ENV === 'production' 4 | 5 | module.exports = { 6 | loaders: utils.cssLoaders({ 7 | sourceMap: isProduction 8 | ? config.build.productionSourceMap 9 | : config.dev.cssSourceMap, 10 | extract: isProduction 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var config = require('../config') 4 | var vueLoaderConfig = require('./vue-loader.conf') 5 | 6 | function resolve (dir) { 7 | return path.join(__dirname, '..', dir) 8 | } 9 | 10 | module.exports = { 11 | entry: { 12 | app: './src/main.js' 13 | }, 14 | output: { 15 | path: config.build.assetsRoot, 16 | filename: '[name].js', 17 | publicPath: process.env.NODE_ENV === 'production' 18 | ? config.build.assetsPublicPath 19 | : config.dev.assetsPublicPath 20 | }, 21 | resolve: { 22 | extensions: ['.js', '.vue', '.json'], 23 | alias: { 24 | 'vue$': 'vue/dist/vue.esm.js', 25 | '@': resolve('src') 26 | } 27 | }, 28 | module: { 29 | rules: [ 30 | { 31 | test: /\.(js|vue)$/, 32 | loader: 'eslint-loader', 33 | enforce: 'pre', 34 | include: [resolve('src'), resolve('test')], 35 | options: { 36 | formatter: require('eslint-friendly-formatter') 37 | } 38 | }, 39 | { 40 | test: /\.vue$/, 41 | loader: 'vue-loader', 42 | options: vueLoaderConfig 43 | }, 44 | { 45 | test: /\.js$/, 46 | loader: 'babel-loader', 47 | include: [resolve('src'), resolve('test')] 48 | }, 49 | { 50 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 51 | loader: 'url-loader', 52 | options: { 53 | limit: 10000, 54 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 55 | } 56 | }, 57 | { 58 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 59 | loader: 'url-loader', 60 | options: { 61 | limit: 10000, 62 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 63 | } 64 | } 65 | ] 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var webpack = require('webpack') 3 | var config = require('../config') 4 | var merge = require('webpack-merge') 5 | var baseWebpackConfig = require('./webpack.base.conf') 6 | var HtmlWebpackPlugin = require('html-webpack-plugin') 7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 8 | 9 | // add hot-reload related code to entry chunks 10 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 11 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 12 | }) 13 | 14 | module.exports = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: '#cheap-module-eval-source-map', 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | 'process.env': config.dev.env 23 | }), 24 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 25 | new webpack.HotModuleReplacementPlugin(), 26 | new webpack.NoEmitOnErrorsPlugin(), 27 | // https://github.com/ampedandwired/html-webpack-plugin 28 | new HtmlWebpackPlugin({ 29 | filename: 'index.html', 30 | template: 'index.html', 31 | inject: true 32 | }), 33 | new FriendlyErrorsPlugin() 34 | ] 35 | }) 36 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var webpack = require('webpack') 4 | var config = require('../config') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var CopyWebpackPlugin = require('copy-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 11 | 12 | var env = config.build.env 13 | 14 | var webpackConfig = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ 17 | sourceMap: config.build.productionSourceMap, 18 | extract: true 19 | }) 20 | }, 21 | devtool: config.build.productionSourceMap ? '#source-map' : false, 22 | output: { 23 | path: config.build.assetsRoot, 24 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 25 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 26 | }, 27 | plugins: [ 28 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 29 | new webpack.DefinePlugin({ 30 | 'process.env': env 31 | }), 32 | new webpack.optimize.UglifyJsPlugin({ 33 | compress: { 34 | warnings: false 35 | }, 36 | sourceMap: true 37 | }), 38 | // extract css into its own file 39 | new ExtractTextPlugin({ 40 | filename: utils.assetsPath('css/[name].[contenthash].css') 41 | }), 42 | // Compress extracted CSS. We are using this plugin so that possible 43 | // duplicated CSS from different components can be deduped. 44 | new OptimizeCSSPlugin({ 45 | cssProcessorOptions: { 46 | safe: true 47 | } 48 | }), 49 | // generate dist index.html with correct asset hash for caching. 50 | // you can customize output by editing /index.html 51 | // see https://github.com/ampedandwired/html-webpack-plugin 52 | new HtmlWebpackPlugin({ 53 | filename: config.build.index, 54 | template: 'index.html', 55 | inject: true, 56 | minify: { 57 | removeComments: true, 58 | collapseWhitespace: true, 59 | removeAttributeQuotes: true 60 | // more options: 61 | // https://github.com/kangax/html-minifier#options-quick-reference 62 | }, 63 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 64 | chunksSortMode: 'dependency' 65 | }), 66 | // split vendor js into its own file 67 | new webpack.optimize.CommonsChunkPlugin({ 68 | name: 'vendor', 69 | minChunks: function (module, count) { 70 | // any required modules inside node_modules are extracted to vendor 71 | return ( 72 | module.resource && 73 | /\.js$/.test(module.resource) && 74 | module.resource.indexOf( 75 | path.join(__dirname, '../node_modules') 76 | ) === 0 77 | ) 78 | } 79 | }), 80 | // extract webpack runtime and module manifest to its own file in order to 81 | // prevent vendor hash from being updated whenever app bundle is updated 82 | new webpack.optimize.CommonsChunkPlugin({ 83 | name: 'manifest', 84 | chunks: ['vendor'] 85 | }), 86 | // copy custom static assets 87 | new CopyWebpackPlugin([ 88 | { 89 | from: path.resolve(__dirname, '../static'), 90 | to: config.build.assetsSubDirectory, 91 | ignore: ['.*'] 92 | } 93 | ]) 94 | ] 95 | }) 96 | 97 | if (config.build.productionGzip) { 98 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 99 | 100 | webpackConfig.plugins.push( 101 | new CompressionWebpackPlugin({ 102 | asset: '[path].gz[query]', 103 | algorithm: 'gzip', 104 | test: new RegExp( 105 | '\\.(' + 106 | config.build.productionGzipExtensions.join('|') + 107 | ')$' 108 | ), 109 | threshold: 10240, 110 | minRatio: 0.8 111 | }) 112 | ) 113 | } 114 | 115 | if (config.build.bundleAnalyzerReport) { 116 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 117 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 118 | } 119 | 120 | module.exports = webpackConfig 121 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '/', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'], 18 | // Run the build command with an extra argument to 19 | // View the bundle analyzer report after build finishes: 20 | // `npm run build --report` 21 | // Set to `true` or `false` to always turn it on or off 22 | bundleAnalyzerReport: process.env.npm_config_report 23 | }, 24 | dev: { 25 | env: require('./dev.env'), 26 | port: 8080, 27 | autoOpenBrowser: true, 28 | assetsSubDirectory: 'static', 29 | assetsPublicPath: '/', 30 | proxyTable: {}, 31 | // CSS Sourcemaps off by default because relative paths are "buggy" 32 | // with this option, according to the CSS-Loader README 33 | // (https://github.com/webpack/css-loader#sourcemaps) 34 | // In our experience, they generally work as expected, 35 | // just be aware of this issue when enabling this option. 36 | cssSourceMap: false 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | startupbattle 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "startupbattle", 3 | "version": "1.0.0", 4 | "description": "A Vue.js project", 5 | "author": "PROSPER OTEMUYIWA ", 6 | "private": true, 7 | "scripts": { 8 | "dev": "node build/dev-server.js", 9 | "build": "node build/build.js", 10 | "lint": "eslint --ext .js,.vue src" 11 | }, 12 | "dependencies": { 13 | "auth0-js": "^9.0.0-beta.5", 14 | "axios": "^0.16.1", 15 | "jquery": "^3.2.1", 16 | "jwt-decode": "^2.2.0", 17 | "vue": "^2.2.2", 18 | "vue-router": "^2.2.0" 19 | }, 20 | "devDependencies": { 21 | "autoprefixer": "^6.7.2", 22 | "babel-core": "^6.22.1", 23 | "babel-eslint": "^7.1.1", 24 | "babel-loader": "^6.2.10", 25 | "babel-plugin-transform-runtime": "^6.22.0", 26 | "babel-preset-env": "^1.2.1", 27 | "babel-preset-stage-2": "^6.22.0", 28 | "babel-register": "^6.22.0", 29 | "chalk": "^1.1.3", 30 | "connect-history-api-fallback": "^1.3.0", 31 | "copy-webpack-plugin": "^4.0.1", 32 | "css-loader": "^0.26.1", 33 | "eslint": "^3.14.1", 34 | "eslint-friendly-formatter": "^2.0.7", 35 | "eslint-loader": "^1.6.1", 36 | "eslint-plugin-html": "^2.0.0", 37 | "eslint-config-airbnb-base": "^11.0.1", 38 | "eslint-import-resolver-webpack": "^0.8.1", 39 | "eslint-plugin-import": "^2.2.0", 40 | "eventsource-polyfill": "^0.9.6", 41 | "express": "^4.14.1", 42 | "extract-text-webpack-plugin": "^2.0.0", 43 | "file-loader": "^0.10.0", 44 | "friendly-errors-webpack-plugin": "^1.1.3", 45 | "function-bind": "^1.1.0", 46 | "html-webpack-plugin": "^2.28.0", 47 | "http-proxy-middleware": "^0.17.3", 48 | "webpack-bundle-analyzer": "^2.2.1", 49 | "semver": "^5.3.0", 50 | "opn": "^4.0.2", 51 | "optimize-css-assets-webpack-plugin": "^1.3.0", 52 | "ora": "^1.1.0", 53 | "rimraf": "^2.6.0", 54 | "url-loader": "^0.5.7", 55 | "vue-loader": "^11.1.4", 56 | "vue-style-loader": "^2.0.0", 57 | "vue-template-compiler": "^2.2.4", 58 | "webpack": "^2.2.1", 59 | "webpack-dev-middleware": "^1.10.0", 60 | "webpack-hot-middleware": "^2.16.1", 61 | "webpack-merge": "^2.6.1" 62 | }, 63 | "engines": { 64 | "node": ">= 4.0.0", 65 | "npm": ">= 3.0.0" 66 | }, 67 | "browserslist": [ 68 | "> 1%", 69 | "last 2 versions", 70 | "not ie <= 8" 71 | ] 72 | } 73 | -------------------------------------------------------------------------------- /server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "startup-battle", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node server.js", 9 | "dev": "nodemon server.js" 10 | }, 11 | "author": "Auth0", 12 | "license": "MIT", 13 | "dependencies": { 14 | "body-parser": "^1.15.2", 15 | "cors": "^2.8.1", 16 | "express": "^4.14.0", 17 | "express-jwt": "^3.4.0", 18 | "jwks-rsa": "^1.1.1" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /server/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const express = require('express'); 4 | const app = express(); 5 | const jwt = require('express-jwt'); 6 | const jwks = require('jwks-rsa'); 7 | const cors = require('cors'); 8 | const bodyParser = require('body-parser'); 9 | 10 | app.use(bodyParser.json()); 11 | app.use(bodyParser.urlencoded({ extended: true })); 12 | app.use(cors()); 13 | 14 | const authCheck = jwt({ 15 | secret: jwks.expressJwtSecret({ 16 | cache: true, 17 | rateLimit: true, 18 | jwksRequestsPerMinute: 5, 19 | jwksUri: "https://{YOUR-AUTH0-DOMAIN}/.well-known/jwks.json" 20 | }), 21 | // This is the identifier we set when we created the API 22 | audience: '{YOUR-API-AUDIENCE-ATTRIBUTE}', 23 | issuer: "https://{YOUR-AUTH0-DOMAIN}.auth0.com/", 24 | algorithms: ['RS256'] 25 | }); 26 | 27 | 28 | app.get('/api/battles/public', (req, res) => { 29 | let publicBattles = [ 30 | { 31 | id: 1111, 32 | name: 'Startup NYC', 33 | sponsor: 'Alec Pesola', 34 | seedFund: '500k' 35 | }, 36 | { 37 | id: 1112, 38 | name: 'Startup Ontario', 39 | sponsor: 'Ryan Chenkie', 40 | seedFund: '750k' 41 | }, 42 | { 43 | id: 1113, 44 | name: 'Startup Uttah', 45 | sponsor: 'Diego Poza', 46 | seedFund: '550k' 47 | }, 48 | { 49 | id: 1114, 50 | name: 'Startup Australia', 51 | sponsor: 'Eugene Kogan', 52 | seedFund: '500k' 53 | }, 54 | { 55 | id: 1115, 56 | name: 'Startup Buenos Aires', 57 | sponsor: 'Sebastian Peyrott', 58 | seedFund: '600k' 59 | }, 60 | { 61 | id: 1116, 62 | name: 'Startup Lagos', 63 | sponsor: 'Prosper Otemuyiwa', 64 | seedFund: '650k' 65 | }, 66 | { 67 | id: 1117, 68 | name: 'Startup Oslo', 69 | sponsor: 'Mark Fish', 70 | seedFund: '600k' 71 | }, 72 | { 73 | id: 1118, 74 | name: 'Startup Calabar', 75 | sponsor: 'Christian Nwamba', 76 | seedFund: '800k' 77 | }, 78 | { 79 | id: 1119, 80 | name: 'Startup Nairobi', 81 | sponsor: 'Aniedi Ubong', 82 | seedFund: '700k' 83 | }]; 84 | 85 | res.json(publicBattles); 86 | }) 87 | 88 | app.get('/api/battles/private', authCheck, (req,res) => { 89 | let privateBattles = [ 90 | { 91 | id: 2111, 92 | name: 'Startup Seattle', 93 | sponsor: 'Mark Zuckerberg', 94 | seedFund: '10M' 95 | }, 96 | { 97 | id: 2112, 98 | name: 'Startup Vegas', 99 | sponsor: 'Bill Gates', 100 | seedFund: '20M' 101 | }, 102 | { 103 | id: 2113, 104 | name: 'Startup Addis-Ababa', 105 | sponsor: 'Aliko Dangote', 106 | seedFund: '8M' 107 | }, 108 | { 109 | id: 2114, 110 | name: 'Startup Abuja', 111 | sponsor: 'Femi Otedola', 112 | seedFund: '5M' 113 | }, 114 | { 115 | id: 2115, 116 | name: 'Startup Paris', 117 | sponsor: 'Jeff Bezos', 118 | seedFund: '1.6M' 119 | }, 120 | { 121 | id: 2116, 122 | name: 'Startup London', 123 | sponsor: 'Dave McClure', 124 | seedFund: '1M' 125 | }, 126 | { 127 | id: 2117, 128 | name: 'Startup Oslo', 129 | sponsor: 'Paul Graham', 130 | seedFund: '2M' 131 | }, 132 | { 133 | id: 2118, 134 | name: 'Startup Bangkok', 135 | sponsor: 'Jeff Clavier', 136 | seedFund: '5M' 137 | }, 138 | { 139 | id: 2119, 140 | name: 'Startup Seoul', 141 | sponsor: 'Paul Buchheit', 142 | seedFund: '4M' 143 | }]; 144 | 145 | res.json(privateBattles); 146 | }) 147 | 148 | app.listen(3333); 149 | console.log('Listening on localhost:3333'); 150 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 15 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-blog/vuejs2-authentication-tutorial/0bd13c82c11b4b9448ed33cc5c245e4f23aefa2d/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/AppNav.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 33 | 34 | 35 | 42 | -------------------------------------------------------------------------------- /src/components/callback.vue: -------------------------------------------------------------------------------- 1 | 3 | 18 | -------------------------------------------------------------------------------- /src/components/privateBattles.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 58 | 59 | 60 | 62 | -------------------------------------------------------------------------------- /src/components/publicBattles.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 61 | 62 | 63 | 65 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue'; 4 | import App from './App'; 5 | import router from './router'; 6 | 7 | Vue.config.productionTip = false; 8 | 9 | /* eslint-disable no-new */ 10 | new Vue({ 11 | el: '#app', 12 | router, 13 | template: '', 14 | components: { App }, 15 | }); 16 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Router from 'vue-router'; 3 | import PrivateBattles from '@/components/privateBattles'; 4 | import PublicBattles from '@/components/publicBattles'; 5 | import Callback from '@/components/callback'; 6 | import { requireAuth } from '../../utils/auth'; 7 | 8 | Vue.use(Router); 9 | 10 | export default new Router({ 11 | mode: 'history', 12 | routes: [ 13 | { 14 | path: '/', 15 | name: 'PublicBattles', 16 | component: PublicBattles, 17 | }, 18 | { 19 | path: '/private-battles', 20 | name: 'PrivateBattles', 21 | beforeEnter: requireAuth, 22 | component: PrivateBattles, 23 | }, 24 | { 25 | path: '/callback', 26 | component: Callback, 27 | }, 28 | ], 29 | }); 30 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-blog/vuejs2-authentication-tutorial/0bd13c82c11b4b9448ed33cc5c245e4f23aefa2d/static/.gitkeep -------------------------------------------------------------------------------- /utils/auth.js: -------------------------------------------------------------------------------- 1 | import decode from 'jwt-decode'; 2 | import axios from 'axios'; 3 | import Router from 'vue-router'; 4 | import auth0 from 'auth0-js'; 5 | const ID_TOKEN_KEY = 'id_token'; 6 | const ACCESS_TOKEN_KEY = 'access_token'; 7 | 8 | const CLIENT_ID = '{AUTH0_CLIENT_ID}'; 9 | const CLIENT_DOMAIN = '{AUTH0_DOMAIN}'; 10 | const REDIRECT = 'YOUR_CALLBACK_URL'; 11 | const SCOPE = '{SCOPE}'; 12 | const AUDIENCE = 'AUDIENCE_ATTRIBUTE'; 13 | 14 | 15 | var auth = new auth0.WebAuth({ 16 | clientID: CLIENT_ID, 17 | domain: CLIENT_DOMAIN 18 | }); 19 | 20 | export function login() { 21 | auth.authorize({ 22 | responseType: 'token id_token', 23 | redirectUri: REDIRECT, 24 | audience: AUDIENCE, 25 | scope: SCOPE 26 | }); 27 | } 28 | 29 | var router = new Router({ 30 | mode: 'history', 31 | }); 32 | 33 | export function logout() { 34 | clearIdToken(); 35 | clearAccessToken(); 36 | router.go('/'); 37 | } 38 | 39 | export function requireAuth(to, from, next) { 40 | if (!isLoggedIn()) { 41 | next({ 42 | path: '/', 43 | query: { redirect: to.fullPath } 44 | }); 45 | } else { 46 | next(); 47 | } 48 | } 49 | 50 | export function getIdToken() { 51 | return localStorage.getItem(ID_TOKEN_KEY); 52 | } 53 | 54 | export function getAccessToken() { 55 | return localStorage.getItem(ACCESS_TOKEN_KEY); 56 | } 57 | 58 | function clearIdToken() { 59 | localStorage.removeItem(ID_TOKEN_KEY); 60 | } 61 | 62 | function clearAccessToken() { 63 | localStorage.removeItem(ACCESS_TOKEN_KEY); 64 | } 65 | 66 | // Helper function that will allow us to extract the access_token and id_token 67 | function getParameterByName(name) { 68 | let match = RegExp('[#&]' + name + '=([^&]*)').exec(window.location.hash); 69 | return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); 70 | } 71 | 72 | // Get and store access_token in local storage 73 | export function setAccessToken() { 74 | let accessToken = getParameterByName('access_token'); 75 | localStorage.setItem(ACCESS_TOKEN_KEY, accessToken); 76 | } 77 | 78 | // Get and store id_token in local storage 79 | export function setIdToken() { 80 | let idToken = getParameterByName('id_token'); 81 | localStorage.setItem(ID_TOKEN_KEY, idToken); 82 | } 83 | 84 | export function isLoggedIn() { 85 | const idToken = getIdToken(); 86 | return !!idToken && !isTokenExpired(idToken); 87 | } 88 | 89 | function getTokenExpirationDate(encodedToken) { 90 | const token = decode(encodedToken); 91 | if (!token.exp) { return null; } 92 | 93 | const date = new Date(0); 94 | date.setUTCSeconds(token.exp); 95 | 96 | return date; 97 | } 98 | 99 | function isTokenExpired(token) { 100 | const expirationDate = getTokenExpirationDate(token); 101 | return expirationDate < new Date(); 102 | } 103 | -------------------------------------------------------------------------------- /utils/battles-api.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import { getAccessToken } from './auth'; 3 | 4 | const BASE_URL = 'http://localhost:3333'; 5 | 6 | export {getPublicStartupBattles, getPrivateStartupBattles}; 7 | 8 | function getPublicStartupBattles() { 9 | const url = `${BASE_URL}/api/battles/public`; 10 | return axios.get(url).then(response => response.data); 11 | } 12 | 13 | function getPrivateStartupBattles() { 14 | const url = `${BASE_URL}/api/battles/private`; 15 | return axios.get(url, { headers: { Authorization: `Bearer ${getAccessToken()}` }}).then(response => response.data); 16 | } 17 | --------------------------------------------------------------------------------