# Quickstart

## Create an Account

1. Create your account on [Inrupt's PodSpaces](https://start.inrupt.com)
2. Save your login credentials securely

## Generate Client Credentials

For simplicity in these first examples, we will interact with the Wallet directly from a backend service via OAuth Client Credentials. User-login via Solid OIDC is covered in [Authentication](https://docs.inrupt.com/security/authentication).

1. Generate client credentials on the [Application Registration](https://login.inrupt.com/registration.html) page
2. Use the client credential to create a session.

```javascript
async function initializeAndLoginSession() {
  const session = new Session();
  await session.login({
    clientId: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    oidcIssuer: "https://login.inrupt.com",
    tokenType: "Bearer",
  });
  
  if (session.info.isLoggedIn && session.info.webId) {
    console.log("Session logged in successfully with WebID");
    return session;
  } else {
    console.error("User is not logged in");
    return null;
  }
}
```

## Add Data to the Wallet

```typescript
async function uploadFile() {
  const session = await initializeAndLoginSession();
  const walletContainer = "https://datawallet.inrupt.com/wallet";
  const path = "path/where/the/file/is/located" + "/text.txt";
  const fileBuffer = await readFile(path);
  const formData = new FormData();
  const file = new File([fileBuffer], path);
  formData.append("file", file);
  formData.append("fileName", fileName);

  const response = await session.fetch(walletContainer, {
    method: "PUT",
    body: formData,
  });

  if (response.status === 200) {
    return "File uploaded successfully";
  } else {
    console.log(response);
  }
}
```

## Get the Wallet Data

```typescript
async function getFile() {
  const session = await initializeAndLoginSession();
  const walletContainer = "https://datawallet.inrupt.com/wallet";
  const file = walletContainer + "/text.txt";
  
  if (!session) {
    throw new Error("Session is undefined");
  }
  
  const response = await session.fetch(file, {
    method: "GET",
  });
  
  if (response.status === 200) {
    const fetchCredential = await response.text();
    return fetchCredential;
  }
}

```

## Delete Data from the Wallet

```typescript
async function deleteFile() {
  const session = await initializeAndLoginSession();
  const walletContainer = "https://datawallet.inrupt.com/wallet";
  const file = walletContainer + "/text.txt";
  
  if (!session) {
    throw new Error("Session is undefined");
  }
  
  const response = await session.fetch(file, {
    method: "DELETE",
  });
  
  if (response.status === 200) {
    return "file deleted successfully";
  }
}
```
