nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 925 forks source link

middleware guest #1696

Open peterramsis opened 2 years ago

peterramsis commented 2 years ago

Version

module: @nuxtjs/auth-next": "5.0.0-1643791578.532b3d6 nuxt: ^2.15.8

Nuxt configuration

mode:

universal

Nuxt configuration

 import colors from 'vuetify/es5/util/colors'

export default {
    // Target: https://go.nuxtjs.dev/config-target
    target: 'static',

    // Global page headers: https://go.nuxtjs.dev/config-head
    head: {
        titleTemplate: '%s - frontend',
        title: 'frontend',
        htmlAttrs: {
            lang: 'en',
        },
        meta: [
            { charset: 'utf-8' },
            { name: 'viewport', content: 'width=device-width, initial-scale=1' },
            { hid: 'description', name: 'description', content: '' },
            { name: 'format-detection', content: 'telephone=no' },
        ],
        link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
    },

    // Global CSS: https://go.nuxtjs.dev/config-css
    css: [],

    // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
    plugins: [
        '~/plugins/mixin/vaildation.js',
        '~/plugins/axios.js',
        '~/plugins/user.js',
        '~/plugins/peter.js'
    ],

    // Auto import components: https://go.nuxtjs.dev/config-components
    components: true,

    // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
    buildModules: [
        // https://go.nuxtjs.dev/vuetify
        '@nuxtjs/vuetify',
    ],

    // Modules: https://go.nuxtjs.dev/config-modules
    modules: [
        // https://go.nuxtjs.dev/axios
        '@nuxtjs/axios',
        '@nuxtjs/auth-next'
    ],

    // Axios module configuration: https://go.nuxtjs.dev/config-axios
    axios: {
        // Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
        baseURL: 'http://127.0.0.1:8000/api',
    },

    router: {
        middleware: ['clearValidationError']
    },

    // Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
    vuetify: {
        customVariables: ['~/assets/variables.scss'],
        theme: {
            dark: true,
            themes: {
                dark: {
                    primary: colors.blue.darken2,
                    accent: colors.grey.darken3,
                    secondary: colors.amber.darken3,
                    info: colors.teal.lighten1,
                    warning: colors.amber.base,
                    error: colors.deepOrange.accent4,
                    success: colors.green.accent3,
                },
            },
        },
    },

    auth: {

        strategies: {
            local: {
                token: {
                    property: 'token',
                    global: true,
                    // required: true,
                    // type: 'Bearer'
                },
                endpoints: {
                    login: { url: 'login', method: 'post', propertyName: 'token' },
                    user: { url: 'me', method: 'get', propertyName: 'data.data' },
                    logout: { url: '/logout', method: 'get', propertyName: false },
                },
            },
        },
        redirect: {
            login: '/inspire',
            home: '/',
            logout: '/inspire',
            callback: '/inspire'
        },
        plugins: ['~/plugins/peter.js'],

    },

    // Build Configuration: https://go.nuxtjs.dev/config-build
    build: {
        // extractCss: true,
        // collapseBooleanAttributes: true,
        // decodeEntities: true,
        // minifyCSS: true,
        // minifyJS: true,
        // processConditionalComments: true,
        // removeEmptyAttributes: true,
        // removeRedundantAttributes: true,
        // trimCustomFragments: true,
        // useShortDoctype: true,
        extend(config, ctx) {
            // if (ctx.isDev && ctx.isClient) {
            //     config.module.rules.push({
            //         enforce: 'pre',
            //         test: /\.(js|vue)$/,
            //         exclude: /(node_modules)/,
            //         options: {
            //             fix: true
            //         }
            //     });
            // }
        },
        minify: {
            collapseBooleanAttributes: true,
            decodeEntities: true,
            minifyCSS: true,
            minifyJS: true,
            processConditionalComments: true,
            removeEmptyAttributes: true,
            removeRedundantAttributes: true,
            trimCustomFragments: true,
            useShortDoctype: true
        }

    },
    // generate: {
    //     minify: false
    // }
}

Reproduction

:warning: without a minimal reproduction we won't be able to look into your issue

What is expected?

What is actually happening?

Steps to reproduce

Additional information

Checklist

Steps to reproduce

What is expected?

What is actually happening?

If I write middleware in page view like this : middleware :['guest'] in npm run generate not working and if I write directly like this working fine

middleware({app,redirect}){ if(app.$auth.loggedIn){ redirect('/home'); } },

Performance analysis?

hieudev-vue commented 2 years ago

i have the same issue

augnustin commented 1 year ago

Same here, middleware doesn't seem to work properly.