Skip to content

Commit

Permalink
feat: typescript rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 24, 2020
2 parents 2f2332f + b0836f2 commit 9fbac88
Show file tree
Hide file tree
Showing 76 changed files with 3,012 additions and 2,445 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
templates/
node_modules
.nuxt
dist
types
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": [
"@nuxtjs/eslint-config-typescript"
],
"rules": {
"require-await": 0,
"no-useless-constructor": 0
}
}
28 changes: 0 additions & 28 deletions .eslintrc.js

This file was deleted.

21 changes: 17 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ jobs:
node: [10]

steps:
- uses: actions/setup-node@v1
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Install required packages
run: |
sudo apt-get update
sudo apt-get install libgbm-dev
sudo apt-get install xvfb
- name: checkout
uses: actions/checkout@master

Expand All @@ -40,8 +47,14 @@ jobs:
- name: Lint
run: yarn lint

- name: Test
- name: Build Module
run: yarn build

- name: Build Fixture
run: yarn nuxt build test/fixture

- name: Tests
run: yarn jest

- name: Coverage
uses: codecov/codecov-action@v1
# - name: Coverage
# uses: codecov/codecov-action@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ coverage
dist
package-lock.json
_book
types
12 changes: 6 additions & 6 deletions examples/api/auth.js → demo/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const refreshTokens = {}
// -- Routes --

// [POST] /login
app.post('/login', (req, res, next) => {
app.post('/login', (req, res) => {
const { username, password } = req.body
const valid = username.length && password === '123'
const expiresIn = 15
Expand Down Expand Up @@ -65,7 +65,7 @@ app.post('/login', (req, res, next) => {
})
})

app.post('/refresh', (req, res, next) => {
app.post('/refresh', (req, res) => {
const { refreshToken } = req.body

if ((refreshToken in refreshTokens)) {
Expand All @@ -86,7 +86,7 @@ app.post('/refresh', (req, res, next) => {

refreshTokens[newRefreshToken] = {
accessToken,
user: user,
user,
clientId: '123'
}

Expand All @@ -102,17 +102,17 @@ app.post('/refresh', (req, res, next) => {
})

// [GET] /user
app.get('/user', (req, res, next) => {
app.get('/user', (req, res) => {
res.json({ user: req.user })
})

// [POST] /logout
app.post('/logout', (req, res, next) => {
app.post('/logout', (_req, res) => {
res.json({ status: 'OK' })
})

// Error handler
app.use((err, req, res, next) => {
app.use((err, _req, res) => {
console.error(err) // eslint-disable-line no-console
res.status(401).send(err + '')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const app = express()
// -- Routes --

// [POST] /token
app.post('/token', (req, res, next) => {
app.post('/token', (_req, res) => {
res.json({
token_type: 'bearer',
access_token: TOKEN_NEVER_EXPIRING,
Expand All @@ -18,19 +18,19 @@ app.post('/token', (req, res, next) => {
})

// [GET] /user
app.get('/userinfo', (req, res, next) => {
app.get('/userinfo', (_req, res) => {
res.json({
"sub" : "83692",
"name" : "Alice Adams",
"email" : "alice@example.com",
"department" : "Engineering",
"birthdate" : "1975-12-31",
"picture" : "https://github.com/nuxt.png"
sub: '83692',
name: 'Alice Adams',
email: 'alice@example.com',
department: 'Engineering',
birthdate: '1975-12-31',
picture: 'https://github.com/nuxt.png'
})
})

// [GET] /cats
app.get('/cats', (req, res, next) => {
app.get('/cats', (_req, res) => {
res.json([
'Tiger', 'Max', 'Smokey'
])
Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="overlay" v-if="$auth.$state.busy">
<img src="~/assets/loading.svg" alt="Loading..." />
</div>
<div v-if="$auth.$state.busy" class="overlay">
<img src="~/assets/loading.svg" alt="Loading...">
</div>
</template>

<style scoped>
Expand Down
38 changes: 26 additions & 12 deletions examples/demo/layouts/default.vue → demo/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
<template>
<div>
<b-navbar toggleable="md" variant="light">
<b-navbar-toggle target="nav_collapse"></b-navbar-toggle>
<b-navbar-brand to="/">Nuxt.js</b-navbar-brand>
<b-navbar-toggle target="nav_collapse" />
<b-navbar-brand to="/">
Nuxt.js
</b-navbar-brand>

<b-collapse is-nav id="nav_collapse">
<b-collapse id="nav_collapse" is-nav>
<b-navbar-nav>
<b-nav-item to="/" exact>Home</b-nav-item>
<b-nav-item to="/public">Public</b-nav-item>
<b-nav-item to="/secure">Secure</b-nav-item>
<b-nav-item to="/oauth2RefreshTest">Oauth2 token refresh test</b-nav-item>
<b-nav-item to="/" exact>
Home
</b-nav-item>
<b-nav-item to="/public">
Public
</b-nav-item>
<b-nav-item to="/secure">
Secure
</b-nav-item>
<b-nav-item to="/oauth2RefreshTest">
Oauth2 token refresh test
</b-nav-item>
</b-navbar-nav>
<b-navbar-nav class="ml-auto">
<template v-if="$auth.$state.loggedIn">
<b-nav-item-dropdown :text="$auth.user.name" right>
<b-dropdown-item @click="$auth.logout()">Logout</b-dropdown-item>
<b-dropdown-item @click="$auth.logout()">
Logout
</b-dropdown-item>
</b-nav-item-dropdown>
<b-img :src="picture" class="mt-1" rounded="circle" width="30px" height="30px" />
</template>
<template v-else>
<b-dropdown-item to="/login">Login</b-dropdown-item>
<b-dropdown-item to="/login">
Login
</b-dropdown-item>
</template>
</b-navbar-nav>
</b-collapse>
Expand All @@ -33,10 +47,10 @@
<script>
import get from 'lodash.get'
export default {
export default {
computed: {
picture() {
return get(this.$auth.user, 'picture') || // OpenID
picture () {
return get(this.$auth.user, 'picture') || // OpenID
get(this.$auth.user, 'picture.data.url') || // Facebook graph API
get(this.$auth.user, 'avatar_url') // GitHub
}
Expand Down
30 changes: 17 additions & 13 deletions examples/demo/nuxt.config.js → demo/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const { resolve } = require('path')
import authModule from '../src/module'

module.exports = {
rootDir: resolve(__dirname, '../..'),
buildDir: resolve(__dirname, '.nuxt'),
srcDir: __dirname,
export default {
build: {
extractCSS: true
},
serverMiddleware: [
'../api/auth',
'../api/oauth2mockserver'
'~/api/auth',
'~/api/oauth2mockserver'
],
buildModules: [
'@nuxt/typescript-build'
],
modules: [
'bootstrap-vue/nuxt',
'@nuxtjs/axios',
authModule
],
modules: ['bootstrap-vue/nuxt', '@nuxtjs/axios', '@@'],
axios: {
proxy: true
},
Expand All @@ -34,7 +38,7 @@ module.exports = {
}
},
localRefresh: {
_scheme: 'refresh',
scheme: 'refresh',
token: {
property: 'token.accessToken',
maxAge: 15
Expand Down Expand Up @@ -71,14 +75,14 @@ module.exports = {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET
},
twitter: {
/* twitter: {
clientId: 'FAJNuxjMTicff6ciDKLiZ4t0D'
},
'laravel.sanctum': {
}, */
laravelSanctum: {
url: '/laravel'
},
oauth2mock: {
_scheme: 'oauth2',
scheme: 'oauth2',
endpoints: {
authorization: '/oauth2mockLogin',
token: '/oauth2mockserver/token',
Expand Down
12 changes: 12 additions & 0 deletions demo/pages/callback.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div class="container d-flex align-items-center justify-content-center flex-column">
<img src="~/assets/loading.svg" alt="Loading..." width="80px">
Logging in...
</div>
</template>

<style scoped>
.container {
min-height: 70vh;
}
</style>
16 changes: 11 additions & 5 deletions examples/demo/pages/index.vue → demo/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
<div>
<b-jumbotron class="text-center">
<h3>Welcome to Nuxt.js auth example</h3>
This demo is using auth-module v{{version}}
This demo is using auth-module v{{ version }}
<div class="mt-1">
<template v-if="$auth.$state.loggedIn">
<b-btn class="ml-3" variant="info" to="/secure">Secure</b-btn>
<b-btn class="ml-3" variant="danger" @click="$auth.logout()">Logout</b-btn>
<b-btn class="ml-3" variant="info" to="/secure">
Secure
</b-btn>
<b-btn class="ml-3" variant="danger" @click="$auth.logout()">
Logout
</b-btn>
</template>
<b-btn variant="success" v-else to="/login">Login</b-btn>
<b-btn v-else variant="success" to="/login">
Login
</b-btn>
</div>
</b-jumbotron>

Expand All @@ -20,7 +26,7 @@
</template>

<script>
import { version } from '../../../package.json'
import { version } from '../../package.json'
export default {
computed: {
Expand Down
Loading

0 comments on commit 9fbac88

Please sign in to comment.