Skip to content

Commit e5bc341

Browse files
committed
refactor(auth): deprecate decodeUserToken in favor of decodeSessionCookie
The name makes more sense. The deprecated method will be removed in the next minor as it is not officially public API
1 parent 4169e8d commit e5bc341

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/nuxt/src/runtime/auth/plugin-user-token.server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { App as AdminApp } from 'firebase-admin/app'
2-
import { decodeUserToken, AUTH_COOKIE_NAME } from 'vuefire/server'
2+
import { decodeSessionCookie, AUTH_COOKIE_NAME } from 'vuefire/server'
33
import { getCookie } from 'h3'
44
import { DECODED_ID_TOKEN_SYMBOL } from '../constants'
55
import { defineNuxtPlugin, useRequestEvent } from '#app'
@@ -11,7 +11,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
1111
const event = useRequestEvent()
1212
const adminApp = nuxtApp.$firebaseAdminApp as AdminApp
1313

14-
const decodedToken = await decodeUserToken(
14+
const decodedToken = await decodeSessionCookie(
1515
getCookie(event, AUTH_COOKIE_NAME),
1616
adminApp
1717
)

src/server/auth.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,24 @@ function warnInvalidServerGetter<T>(name: string, value: T) {
103103
* Verifies a cookie token and returns the corresponding decoded token or null if the token is invalid or inexistent.
104104
* This token contains the user's uid.
105105
*
106-
* @param token - token parsed from the cookie
106+
* @param sessionCookie - token parsed from the cookie
107107
* @param adminApp - Firebase Admin App
108108
*/
109-
export async function decodeUserToken(
110-
token: string | undefined,
109+
export async function decodeSessionCookie(
110+
sessionCookie: string | undefined,
111111
adminApp: AdminApp
112112
): Promise<DecodedIdToken | null> {
113-
if (token) {
113+
if (sessionCookie) {
114114
const adminAuth = getAdminAuth(adminApp)
115115

116116
try {
117117
// TODO: should we check for the revoked status of the token here?
118118
// we await to try/catch
119119
// return await adminAuth.verifyIdToken(token /*, checkRevoked */)
120-
return await adminAuth.verifySessionCookie(token /** checkRevoked */)
120+
return await adminAuth.verifySessionCookie(
121+
sessionCookie
122+
/** checkRevoked */
123+
)
121124
} catch (err) {
122125
// TODO: some errors should probably go higher
123126
// ignore the error and consider the user as not logged in
@@ -135,3 +138,8 @@ export async function decodeUserToken(
135138

136139
return null
137140
}
141+
142+
/**
143+
* @deprecated Use `decodeSessionCookie` instead.
144+
*/
145+
export const decodeUserToken = decodeSessionCookie

src/server/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export {
33
VueFireAuthServer,
44
createServerUser,
55
AUTH_COOKIE_NAME,
6+
decodeSessionCookie,
67
decodeUserToken,
78
} from './auth'
89
export { getAdminApp } from './admin'

0 commit comments

Comments
 (0)