Skip to content

Commit 88f4f8e

Browse files
committed
fix: missing upstash creds legacy
1 parent fdf8335 commit 88f4f8e

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

nuxt.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export default defineNuxtConfig({
8383
password: process.env.REDIS_PASSWORD,
8484
},
8585

86+
upstash: {
87+
url: process.env.UPSTASH_REDIS_REST_URL,
88+
token: process.env.UPSTASH_REDIS_REST_TOKEN,
89+
},
90+
8691
public: {
8792
appVersion,
8893
appCredit: process.env.NUXT_PUBLIC_APP_CREDIT || 'Thecodeorigin',
@@ -342,6 +347,10 @@ export default defineNuxtConfig({
342347
? {
343348
driver: {
344349
name: 'upstash',
350+
options: {
351+
url: process.env.UPSTASH_REDIS_REST_URL,
352+
token: process.env.UPSTASH_REDIS_REST_TOKEN,
353+
},
345354
},
346355
}
347356
: process.env.REDIS_HOST && process.env.REDIS_PASSWORD

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thecodeorigin/nuxt",
33
"type": "module",
4-
"version": "1.11.7",
4+
"version": "1.11.8",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org",
77
"access": "public"

server/plugins/redis.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export default defineNitroPlugin(() => {
77
if (process.env.UPSTASH_REDIS_REST_URL && process.env.UPSTASH_REDIS_REST_TOKEN) {
88
const driver = upstashDriver({
99
base: 'redis',
10+
url: process.env.UPSTASH_REDIS_REST_URL,
11+
token: process.env.UPSTASH_REDIS_REST_TOKEN,
1012
})
1113

1214
storage.mount('redis', driver)

server/utils/storage.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { TransactionOptions } from 'unstorage'
2+
13
export function getStorageSessionKey(providerAccountId: string) {
24
return `session:${providerAccountId}`
35
}
@@ -9,14 +11,14 @@ export function getStorageStripeKey(identifier: string) {
911
function getStorage() {
1012
const config = useRuntimeConfig()
1113

12-
return (config.redis.host && config.redis.port && config.redis.password)
14+
return ((config.redis.host && config.redis.port && config.redis.password) || (config.upstash.url && config.upstash.token))
1315
? useStorage('redis')
1416
: config.mongodb.connectionString
1517
? useStorage('mongodb')
1618
: useStorage()
1719
}
1820

19-
export async function tryWithCache<T>(key: string, getter: () => Promise<T | undefined | null>) {
21+
export async function tryWithCache<T>(key: string, getter: () => Promise<T | undefined | null>, options?: TransactionOptions) {
2022
const storage = getStorage()
2123

2224
const cachedResult = await storage.getItem(key)
@@ -27,7 +29,7 @@ export async function tryWithCache<T>(key: string, getter: () => Promise<T | und
2729
const result = await getter()
2830

2931
if (Array.isArray(result) ? result.length : result)
30-
await storage.setItem(key, result as any)
32+
await storage.setItem(key, result as any, options)
3133

3234
return result as T
3335
}

0 commit comments

Comments
 (0)