Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to do Client only auth with SSR #1564

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alexandresanchograca
Copy link

@alexandresanchograca alexandresanchograca commented Aug 13, 2024

In my usage I found it lacked the need to support client only Auth with SSR. Currently I only want to do authentication on the client, but still want to fetch firestore data that doesn't require an authenticated user to be able to retrieve this data on the server.

This change should be compatible with all the old versions without any breaking changes.
To only allow authentication on the client during SSR:

    auth: {
      enabled: true,
      clientOnly: true
    }

Before this would require an admin service-account to be included in your project so that the app could fetch the server data, with this check we disable the loading of the plugin-authenticate-user.server, and can start a firebase app on the server without firebaseAuth and retrieve public/accessible data of firestore without needing an authorisation.
When on the client the authorisation will remain enabled and the rest of the data that requires authorisation will be loaded client only.

… This is because we might want do SSR without server authentication, authentication only on the client, since many firestore data are not restricted by authorization or authentication of a user.
@@ -208,7 +208,9 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
}

// loads the user on the current app
addPlugin(resolve(runtimeDir, 'auth/plugin-authenticate-user.server'))
if(!options.auth.clientOnly){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!options.auth.clientOnly){
if (!options.auth.clientOnly) {

Is the key always set on auth?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clientOnly key?
If the key is not set it executes the previously default behaviour of loading the auth/plugin-authenticate-user.server.

Formatted code

Co-authored-by: Daniel Kudwien <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants