Skip to content

Commit

Permalink
Add protectRoute arg to getSession
Browse files Browse the repository at this point in the history
  • Loading branch information
tedspare committed Jan 6, 2025
1 parent 65a3b72 commit 74279f2
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [2025-01-06] [Add protectRoute arg to getSession](https://github.com/RubricLab/auth/commit/76aa6c4df2d26fba87df6a89327991fcef06afb7)
- [2024-10-31] [next auth 15 support awaited cookies](https://github.com/RubricLab/auth/commit/8444c6e86d48c4ab7b180e2001ad1fd713a6684d)
- [2024-10-24] [add notify-monorepo action](https://github.com/RubricLab/auth/commit/d111b1ebaca5f3599f8477a5c61e15db60d86238)
- [2024-10-18] [assert getSession has user or redirect to unauth url](https://github.com/RubricLab/auth/commit/939bc637013933cbbcb03f00753ebcbe500759bd)
4 changes: 2 additions & 2 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ export function createAuthActions({
})
},

async getSession() {
async getSession({ protectedRoute = true }: { protectedRoute?: boolean } = {}) {
const user = JSON.parse((await cookies()).get('user')?.value || '{}')

const sessionKey = (await cookies()).get('key')?.value
@@ -73,7 +73,7 @@ export function createAuthActions({
user
})

if (!success) {
if (!success && protectedRoute) {
redirect(unauthorizedUrl)
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
"lint:fix": "bun x biome check --fix --unsafe . && bun x biome lint --write --unsafe ."
},
"name": "@rubriclab/auth",
"version": "0.0.10",
"version": "0.0.11",
"main": "index.ts",
"dependencies": {
"@rubriclab/package": "*",

0 comments on commit 74279f2

Please sign in to comment.