
Product
Introducing Custom Pull Request Alert Comment Headers
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
@duotek/nuxt3-auth
Advanced tools
yarn add -E @duotek/nuxt3-auth
export default defineNuxtConfig({
modules: ["@duotek/nuxt3-auth"],
});
export default defineNuxtConfig({
auth: {
redirects: { // опциональный параметр для работы middleware
auth: false, // передается строка страницы для редиректа авторизованного пользователя или false для пропуска
guest: false, // передается строка страницы для редиректа неавторизованного пользователя или false для пропуска
external: false, // дает возможность редиректить пользователя по внешним ссылкам
externalDomain: '', // домен куки для редиректа внутри домена
},
cookie: { // обязательный параметр для сохранения токена
prefix: "",
options: {
expires: 300, // дней
domain: '.example.com' // опционально; возможность создать кросдоменную куку
},
},
strategies: { // требуется хотя бы одна стратегия для использования плагина
signUp: { // название стратегии регистрации, не изменяется
tokenType: "",
endpoints: {
login: {
url: "",
method: "",
propertyName: "",
},
logout: {
url: "",
method: "",
},
user: { // необязательный параметр, если не передать, пользователь не будет запрашиваться и сохраняться
url: "",
method: "",
},
},
},
signIn: { // название стратегии логина, не изменяется
tokenType: "",
endpoints: {
login: {
url: "",
method: "",
propertyName: "",
},
logout: {
url: "",
method: "",
},
user: { // необязательный параметр, если не передать, пользователь не будет запрашиваться и сохраняться
url: "",
method: "",
},
},
},
},
},
});
export default defineNuxtConfig({
runtimeConfig: {
public: {
app_env: {
BASE_API_URL: "https://api-example.com",
},
},
},
});
// Используйте свой вариант
import { useNuxtApp, useFetch } from '#app';
export function useAuthFetch(url, options = {}) {
const { $authFetch } = useNuxtApp();
return useFetch(url, {
...options,
$fetch: $authFetch,
});
}
import { useCustomFetch } from '~/path/to/useCustomFetch';
const { data, error } = await useCustomFetch('/some-endpoint');
// Или расширьте $fetch своими эндпоинтами
// файл services/index.js
import createApi from '~/services/api/index';
export default defineNuxtPlugin((nuxtApp) => {
if (!nuxtApp.$api) {
const { $authFetch } = useNuxtApp();
const apiObject = createApi({
$api: $authFetch,
$config: useRuntimeConfig().public.app_env,
});
nuxtApp.provide('api', apiObject);
}
});
// файл services/api/index.js
import RExample from '@/services/api/resource/RExample';
const createApi = (ctx) => ({
example: new RExample(ctx),
});
export default createApi;
<template>
<div>
<div v-if="isLoggedIn">
<p>Добро пожаловать, {{ user.name }}</p>
<button @click="onLogout">Выйти</button>
</div>
<div v-else>
<div>Логин</div>
<form @submit.prevent="onSubmit">
<input v-model="login" type="text" placeholder="Логин" />
<input v-model="password" type="password" placeholder="Пароль" />
<button type="submit">Войти</button>
</form>
</div>
</div>
</template>
<script setup>
import { ref, computed } from "vue";
import { useNuxtApp } from "#app";
// Раскомментируйте одну из строк ниже в зависимости от необходимого middleware
// definePageMeta({
// middleware: "guest",
// });
// definePageMeta({
// middleware: "auth",
// });
const login = ref("");
const password = ref("");
const { $auth } = useNuxtApp();
const user = computed(() => $auth.user);
const isLoggedIn = computed(() => $auth.isLoggedIn);
const onSubmit = async () => {
try {
await $auth.signIn({ login: login.value, password: password.value });
} catch (error) {
console.error(error);
}
};
const onLogout = async () => {
await $auth.logout();
};
</script>
# Install dependencies
yarn install
# Generate type stubs
yarn dev:prepare
# Develop with the playground
yarn dev
# Build the playground
yarn dev:build
# Run ESLint
yarn lint
# Run Vitest
yarn test
yarn test:watch
# Release new version
npm publish
FAQs
Duotek Nuxt3 Auth Module
We found that @duotek/nuxt3-auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.