
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
nuxt-oauth
Advanced tools
nuxt-oauth Simple OAuth2 integration for your Nuxt app
yarn add nuxt-oauth
nuxt.config.js
and configure:// nuxt.config.js
modules: ['nuxt-oauth'],
oauth: {
sessionName: 'mySession',
secretKey: process.env.SECRET_KEY,
oauthHost: process.env.OAUTH_HOST,
oauthClientID: process.env.OAUTH_CLIENT_ID,
oauthClientSecret: process.env.OAUTH_CLIENT_SECRET,
onLogout: (req, res) => {
// do something after logging out
},
fetchUser: (accessToken, request) => {
// do something to return the user
const user = User.findByToken(accessToken, request)
return user
}
}
// any-component.vue
export default {
mounted () {
const { accessToken } = this.$store.state.oauth
// fetch more details from somewhere...
}
}
nuxt-oauth
will ensure users are logged in before accessing these pages):// secret.vue
export default {
authenticated: true,
name: 'MySecretComponent'
}
Option | Required? | Description |
---|---|---|
sessionName | * | Configure the name of the cookie that nuxt-oauth uses |
secretKey | * | Provide a secret key to sign the encrypted cookie. Do not leak this! |
oauthHost | * | Host of your OAuth provider (usually ending in oauth or oauth2 ). Can be string or function receiving args (req) |
oauthClientID | * | Client ID of your application, registered with your OAuth provider. Can be string or function receiving args (req) |
oauthClientSecret | * | Client ID of your application, registered with your OAuth provider. Can be string or function receiving args (req) |
scopes | An array of scopes to authenticate against | |
authorizationPath | The path to redirect users to authenticate (defaults to /authorize ) | |
accessTokenPath | The path to request the access token (defaults to /token ) | |
moduleName | The name of the vuex module to be created by nuxt-oauth. (defaults to oauth ) | |
sessionDuration | The duration of the login session. (defaults to 24 hours) | |
onLogout | Optional hook which is called after logging out. E.g. can be used to perform a full log out on your OAuth provider. Receives args (req, res, redirectUrl) . Can be asynchronous (or return a promise). | |
fetchUser | Optional hook which is called when logging in to fetch your user object. Receives args (accessToken, request, options) . | |
testMode | Flag which tells the module to ignore the OAuth dance and log every one in (see here for more). | |
pageComponentPath | Optional page component path to replace the default page provided by this library. |
To dynamically set configuration at runtime, oauthHost
, oauthClientID
, oauthClientSecret
can be strings but also can be async
functions which accept req
as their only argument. This can be useful to choose configuration based on the URL or headers of the request.
You can also use the functionality manually. nuxt-oauth
injects the following helpers into your store, components and ctx.app
: $login
and $logout
. Use these to manually log your user in or out.
Following a successful login/logout, your user will be redirected back to the page from which the helper was called (you can pass a redirectUrl
to the helpers to override this). For a full example, see below.
<!-- any-component.vue -->
<template>
<a @click="logout" v-if="loggedIn">Log Out</a>
<a @click="login" v-else>Log In</a>
</template>
<script>
export default {
asyncData({ app }) {
// Use from context
app.$login()
}
computed () {
loggedIn () {
return this.$store.state.oauth.accessToken
}
},
methods: {
login () {
// defaults to redirecting back to the current page
this.$login()
},
logout () {
// customise the redirrect url
const redirectUrl = '/my-target-path'
this.$logout(redirectUrl)
}
}
}
</script>
Set options.oauth.testMode
to true
to tell the module to skip authentication. Using this, along with the fetchUser
option, can be helpful in e2e tests to stub your test users.
git clone git@github.com:SohoHouse/nuxt-oauth.git
cd nuxt-oauth
yarn
yarn test
# To use while developing other apps:
yarn link
cd ../my-other-app
yarn link nuxt-oauth
To run the fixture Nuxt app (/test/e2e/fixture
) locally, make sure to:
cp .env.example .env
and populate with your real values. Then, run:
yarn dev
To boot the app locally.
Bug reports and pull requests are welcome on GitHub at https://github.com/SohoHouse/nuxt-oauth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The module is available as open source under the terms of the MIT License.
FAQs
OAuth module for your Nuxt applications
The npm package nuxt-oauth receives a total of 25 weekly downloads. As such, nuxt-oauth popularity was classified as not popular.
We found that nuxt-oauth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.