fix(auth-js): Update @auth/core version and set default basePath (#359)

* Update @auth/core version and set default basePath

* update changeset
pull/360/head
divyam234 2024-01-27 18:45:06 +05:30 committed by GitHub
parent 7701152c2a
commit 4ccda19d31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 10 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/auth-js': patch
---
Update @auth/core version and set default basePath

View File

@ -57,7 +57,7 @@
"react": ">=18" "react": ">=18"
}, },
"devDependencies": { "devDependencies": {
"@auth/core": "^0.19.0", "@auth/core": "^0.24.0",
"@types/react": "^18", "@types/react": "^18",
"hono": "^3.11.7", "hono": "^3.11.7",
"jest": "^29.7.0", "jest": "^29.7.0",

View File

@ -35,6 +35,7 @@ function reqWithEnvUrl(req: Request, authUrl?: string): Request {
function setEnvDefaults(env: AuthEnv, config: AuthConfig) { function setEnvDefaults(env: AuthEnv, config: AuthConfig) {
config.secret ??= env.AUTH_SECRET config.secret ??= env.AUTH_SECRET
config.basePath ??= '/api/auth'
config.trustHost = true config.trustHost = true
config.redirectProxyUrl ??= env.AUTH_REDIRECT_PROXY_URL config.redirectProxyUrl ??= env.AUTH_REDIRECT_PROXY_URL
config.providers = config.providers.map((p) => { config.providers = config.providers.map((p) => {
@ -53,13 +54,12 @@ function setEnvDefaults(env: AuthEnv, config: AuthConfig) {
export async function getAuthUser(c: Context): Promise<AuthUser | null> { export async function getAuthUser(c: Context): Promise<AuthUser | null> {
const config = c.get('authConfig') const config = c.get('authConfig')
setEnvDefaults(c.env, config)
const origin = new URL(c.req.url, c.env.AUTH_URL).origin const origin = new URL(c.req.url, c.env.AUTH_URL).origin
const request = new Request(`${origin}/session`, { const request = new Request(`${origin}${config.basePath}/session`, {
headers: { cookie: c.req.header('cookie') ?? '' }, headers: { cookie: c.req.header('cookie') ?? '' },
}) })
setEnvDefaults(c.env, config)
let authUser: AuthUser = {} as AuthUser let authUser: AuthUser = {} as AuthUser
const response = (await Auth(request, { const response = (await Auth(request, {
@ -70,7 +70,6 @@ export async function getAuthUser(c: Context): Promise<AuthUser | null> {
authUser = args[0] authUser = args[0]
const session = const session =
(await config.callbacks?.session?.(...args)) ?? args[0].session (await config.callbacks?.session?.(...args)) ?? args[0].session
// @ts-expect-error either user or token will be defined
const user = args[0].user ?? args[0].token const user = args[0].user ?? args[0].token
return { user, ...session } satisfies Session return { user, ...session } satisfies Session
}, },

View File

@ -45,9 +45,9 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@auth/core@npm:^0.19.0": "@auth/core@npm:^0.24.0":
version: 0.19.0 version: 0.24.0
resolution: "@auth/core@npm:0.19.0" resolution: "@auth/core@npm:0.24.0"
dependencies: dependencies:
"@panva/hkdf": "npm:^1.1.1" "@panva/hkdf": "npm:^1.1.1"
"@types/cookie": "npm:0.6.0" "@types/cookie": "npm:0.6.0"
@ -61,7 +61,7 @@ __metadata:
peerDependenciesMeta: peerDependenciesMeta:
nodemailer: nodemailer:
optional: true optional: true
checksum: 27fc81a2e4348fb6a44ded8137001908c4dfbe0fd0375b1479f50d9ea5be73b5fad20f4338c0e3df1eac4200b3831a7a57cfb79fdcad5a2ce1ce04ff76ad9190 checksum: b8d8c66bc35d18a6ffa80e21b122747cb0c40826f68eb8c22a1b4dda01aba62c2050a1d5e4997e92a6756edad4103faafe8d9a49c7278d991e690c3ebbdb6035
languageName: node languageName: node
linkType: hard linkType: hard
@ -1364,7 +1364,7 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@hono/auth-js@workspace:packages/auth-js" resolution: "@hono/auth-js@workspace:packages/auth-js"
dependencies: dependencies:
"@auth/core": "npm:^0.19.0" "@auth/core": "npm:^0.24.0"
"@types/react": "npm:^18" "@types/react": "npm:^18"
hono: "npm:^3.11.7" hono: "npm:^3.11.7"
jest: "npm:^29.7.0" jest: "npm:^29.7.0"