Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
add: README
Browse files Browse the repository at this point in the history
  • Loading branch information
abishekk92 committed Apr 4, 2023
1 parent f73ed57 commit 06cf234
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions programs/gpl_session/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
GPL Session
==============

Manage sessions in your Solana Anchor Programs.


# Installation

```bash
cargo add gpl-session --features no-entrypoint
```

# Usage

1. Import the dependencies

```rust
use gpl_session::{SessionError, SessionToken, session_auth_or, Session};
```

2. Derive the `Session` trait on your instruction struct

```rust
#[derive(Accounts, Session)]
pub struct Instruction<'info> {
.....
pub user: Account<'info, User>,

#[session(
signer = authority,
authority = user.authority.key()
)]
pub session_token: Option<Account<'info, SessionToken>>,

#[account(mut)]
pub authority: Signer<'info>,
.....
}
```

3. Add the `session_auth_or` macro to your instruction handler with fallback logic on who the instruction should validate the signer when sessions are not present and an appropirate ErrorCode. If you've used `require*!` macros in anchor_lang you already know how this works.

```rust
#[session_auth_or(
ctx.accounts.user.authority.key() == ctx.accounts.authority.key(),
ErrorCode
)]
pub fn ix_handler(ctx: Context<Instruction>,) -> Result<()> {
.....
}

```

0 comments on commit 06cf234

Please sign in to comment.