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

feat(#854): Add getServerSession and getToken to the local provider #855

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

Conversation

zoey-kaiser
Copy link
Member

@zoey-kaiser zoey-kaiser commented Aug 9, 2024

πŸ”— Linked issue

Closes #854

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Adds getServerSession and getToken to the server-side ultis for the local provider.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

@zoey-kaiser zoey-kaiser added enhancement An improvement that needs to be added provider-local An issue with the local provider provider-refresh An issue with the refresh provider labels Aug 10, 2024
@zoey-kaiser zoey-kaiser changed the title feat(#854): Add getServerSession and getToken to the local-provider feat(#854): Add getServerSession and getToken to the local and refresh-provider Aug 10, 2024
@zoey-kaiser zoey-kaiser changed the title feat(#854): Add getServerSession and getToken to the local and refresh-provider feat(#854): Add getServerSession and getToken to the local provider Aug 22, 2024
Copy link

pkg-pr-new bot commented Aug 25, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@sidebase/nuxt-auth@855

commit: 868672d

const providerSpecificTypes: string[] = []

if (provider.type === 'authjs') {
providerSpecificTypes.push(` const { getServerSession, getToken, NuxtAuthHandler }: typeof import('${resolve('./runtime/server/services/authjs')}')`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question - does this resolve relative to current path or from root? From the docs, it looks like the resolution will happen from the current path which is not correct:
https://nuxt.com/docs/api/advanced/import-meta#builder-properties

Comment on lines +11 to +14
if (!token) {
return null
}
return token
Copy link
Collaborator

Choose a reason for hiding this comment

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

formatToken already returns string | null

Suggested change
if (!token) {
return null
}
return token
return token

import { formatToken } from '../../../utils/local'
import { useRuntimeConfig } from '#imports'

export function getToken(event: H3Event) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export function getToken(event: H3Event) {
export function getToken(event: H3Event): string | null {

import type { SessionData } from '#auth'
import { useRuntimeConfig } from '#imports'

function joinPathToApiURL(event: H3Event, path: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: would prefer if this was down the file as it is a helper (consumers are more interested in reading getServerSession

baseURL = fullBaseUrl
}
else {
// Case 2: An origin was not supplied, we determine it from the request
Copy link
Collaborator

Choose a reason for hiding this comment

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

This probably needs to happen only when trustHost is set (look at authjs implementation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement that needs to be added provider-local An issue with the local provider provider-refresh An issue with the refresh provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add server-side access to tokens and session for the local and refresh providers
2 participants