sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.25k stars 162 forks source link

feat(#821): Unify `local` and `refresh` providers into one #822

Closed zoey-kaiser closed 1 month ago

zoey-kaiser commented 2 months ago

๐Ÿ”— Linked issue

closes #821, #730 improved on #731

โ“ Type of change

๐Ÿ“š Description

Removes the separation of the local and refresh providers and adds the extended logic from the refresh provider into an additional refresh config property of the local provider

Simple migration guide:

export default defineNuxtConfig({
    auth: {
        provider: {
-           type: 'refresh',
+           type: 'local',
            endpoints: {
                signIn: { path: '/signIn', method: 'post' },
-               refresh: { path: '/refresh', method: 'post' } 
            },
-           refreshToken: { // Refresh token config },
-           refreshOnlyToken: true,
+           refresh: {
+               isEnabled: true,
+               endpoint:  { path: '/refresh', method: 'post' },
+               refreshOnlyToken: true,
+               token: { // Refresh token config },
+           }
        }
    }
})

New local with refresh config:

export default defineNuxtConfig({
    auth: {
        provider: {
        type: 'local',
            pages: {
                login: '/login'
            },
            endpoints: {
                signIn: { path: '/login', method: 'post' },
                signOut: { path: '/logout', method: 'post' },
                signUp: { path: '/register', method: 'post' },
                getSession: { path: '/session', method: 'get' }
            },
            token: {
                signInResponseTokenPointer: '/token',
                type: 'Bearer',
                cookieName: 'auth.token',
                headerName: 'Authorization',
                maxAgeInSeconds: 30 * 60, // 30 minutes
                sameSiteAttribute: 'lax',
                secureCookieAttribute: false,
                cookieDomain: ''
            },
            session: {
                dataType: { id: 'string | number' },
                dataResponsePointer: '/'
            },
            refresh: {
                isEnabled: true,
                endpoint:  { path: '/refresh', method: 'post' },
                refreshOnlyToken: true,
                token: {
                    signInResponseRefreshTokenPointer: '/refreshToken',
                    refreshRequestTokenPointer: '/refreshToken',
                    cookieName: 'auth.refresh-token',
                    maxAgeInSeconds: 60 * 60 * 24 * 7, // 7 days
                    sameSiteAttribute: 'lax',
                    secureCookieAttribute: false,
                    cookieDomain: ''
                }
        }
        }
    }
})

๐Ÿ“ Checklist