Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
dressly: add parse cookies and jwt decoded
Browse files Browse the repository at this point in the history
  • Loading branch information
khafidprayoga committed Oct 4, 2024
1 parent 501efa3 commit cd3c98a
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 9 deletions.
1 change: 1 addition & 0 deletions dressly/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PUBLIC_CF_ACCESS=khafidprayoga.cloudflareaccess.com
Binary file modified dressly/bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions dressly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"svelte-check": "svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"axios": "^1.7.7",
"js-cookie": "^3.0.5",
"jwt-decode": "^4.0.0",
"lucide-svelte": "^0.447.0",
"svelte": "^4.2.19",
"vanilla-lazyload": "^19.1.3"
Expand All @@ -21,6 +24,7 @@
"@rsbuild/plugin-image-compress": "^1.0.2",
"@rsbuild/plugin-svelte": "^1.0.1",
"@selemondev/svelte-marquee": "^0.0.2",
"@types/js-cookie": "^3.0.6",
"add": "^2.0.6",
"autoprefixer": "^10.4.20",
"eslint": "^9.10.0",
Expand Down
16 changes: 12 additions & 4 deletions dressly/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { defineConfig } from '@rsbuild/core';
import { RsbuildConfig, defineConfig, loadEnv } from '@rsbuild/core';
import { pluginSvelte, PluginSvelteOptions } from '@rsbuild/plugin-svelte';
import { pluginImageCompress } from "@rsbuild/plugin-image-compress";

const { parsed, publicVars } = loadEnv();


const svelteConfig: PluginSvelteOptions = {
svelteLoaderOptions: {},
preprocessOptions: {
Expand All @@ -10,7 +13,7 @@ const svelteConfig: PluginSvelteOptions = {
};


export default defineConfig({
const Config: RsbuildConfig = {
plugins: [pluginSvelte(svelteConfig), pluginImageCompress(['png','svg'])],
html: {
title: 'DressLy - Discover the Latest Fashion Trends',
Expand All @@ -29,5 +32,10 @@ export default defineConfig({
},
output:{
polyfill: 'usage',
}
});
},
source: {
define: parsed,
},
}

export default defineConfig(Config);
20 changes: 16 additions & 4 deletions dressly/src/components/Header/ActionIcon.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
<script>
import { search, cart, account, menu } from '@icons/index';
<script lang="ts">
import { search, cart, account, } from '@icons/index';
import { userData } from '@store/auth';
$: userName = $userData.email;
</script>

<div class="flex items-center space-x-4">
<button
class="hidden md:block text-gray-700 hover:text-gray-900 hover:bg-gray-100 px-3 py-2 rounded-md"
aria-label="Search"
>
<img src={search} alt="Search" class="h-6 w-6" />
</button>
<button class="text-gray-700 hover:text-gray-900 hover:bg-gray-200 px-3 py-2 rounded-md" aria-label="Shopping cart">
<button
class="text-gray-700 hover:text-gray-900 hover:bg-gray-200 px-3 py-2 rounded-md"
aria-label="Shopping cart"
>
<img src={cart} alt="Shopping cart" class="h-6 w-6" />
</button>
<button
class="hidden md:block text-gray-700 hover:text-gray-900 hover:bg-gray-200 px-3 py-2 rounded-md"
aria-label="User account"
>
<img src={account} alt="User Account Login" class="w-6 h-6" />
<img src={account} alt="User Account " class="w-6 h-6" />
</button>
{#if userName}
<span class="hidden sm:inline-block font-thin font-OpenSans"
>{userName}</span
>
{/if}
</div>
29 changes: 29 additions & 0 deletions dressly/src/config/session/cloudflare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export interface SessionData {
id: number
name: string
email: string
groups: any[]
idp: Idp
geo: Geo
user_uuid: string
account_id: string
iat: number
ip: string
auth_status: string
common_name: string
service_token_id: string
service_token_status: boolean
is_warp: boolean
is_gateway: boolean
version: number
}

export interface Idp {
id: string
type: string
}

export interface Geo {
country: string
}

6 changes: 6 additions & 0 deletions dressly/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import App from './App.svelte';
import './index.css';
import { getAuthorizationToken, userData } from '@store/auth';

let creds = getAuthorizationToken();
if (creds) {
userData.set(creds);
}

const app = new App({
target: document.body,
Expand Down
33 changes: 33 additions & 0 deletions dressly/src/store/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Cookies from "js-cookie";
import { jwtDecode } from 'jwt-decode';

import { writable } from 'svelte/store';
let defaultUserData = {} as JWTPayload;
export const userData = writable(defaultUserData);
export function getAuthorizationToken() {
let jwt = Cookies.get("CF_Authorization") || null;
if (!jwt) {
return null;
}

const decoded: JWTPayload = jwtDecode(jwt, );

return decoded
}


export interface JWTPayload {
aud: string[]
email: string
exp: number
iat: number
nbf: number
iss: string
type: string
identity_nonce: string
sub: string
pathCookie: boolean
pathText: string
country: string
}

3 changes: 2 additions & 1 deletion dressly/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"@brand/*": ["./src/assets/brand/*"],
"@icons/*": ["./src/assets/icons/*"],
"@components/*": ["./src/components/*"],
"@store/*": ["./src/store/*"]
"@store/*": ["./src/store/*"],
"@config/*": ["./src/config/*"]
}
},
"include": ["src"]
Expand Down

0 comments on commit cd3c98a

Please sign in to comment.