Skip to content

Commit

Permalink
feat: upgrade cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoSM committed Sep 23, 2023
1 parent 01bf039 commit ffcf206
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 823 deletions.
12 changes: 8 additions & 4 deletions apps/app/middleware/session.global.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { useCookies } from "@vueuse/integrations/useCookies";

export default defineNuxtRouteMiddleware(async (to) => {
if (to.query.oauth) return;

const sessionStore = useSessionStore();
const userStore = useUserStore();

const userCookie: Ref<typeof userStore.user> = useCookie("m-user");
if (userCookie.value) {
userStore.user = userCookie.value;
const userCookie = useCookies([]);
const userCookieValue = userCookie.get("m-user");
if (userCookieValue) {
userStore.user = userCookieValue;
console.log({ userCookieValue });
}

const serverHasSession = userCookie.value || sessionStore.hasSession();
const serverHasSession = sessionStore.hasSession();

if (["profile"].includes(String(to.name)) && !serverHasSession) {
return navigateTo("/sign-in");
Expand Down
1 change: 0 additions & 1 deletion apps/app/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export default defineNuxtConfig({
"nuxt-schema-org",
"@nuxtjs/fontaine",
"@nuxt/content",
"@vueuse/nuxt",
"@pinia/nuxt",
],
vite: {
Expand Down
9 changes: 5 additions & 4 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@nuxt/content": "^2.7.2",
"@nuxt/content": "^2.8.2",
"@nuxtjs/fontaine": "^0.2.5",
"@types/node": "^20.4.6",
"nuxt": "3.5.3",
"nuxt": "^3.7.3",
"nuxt-schema-org": "^2.1.3",
"typescript": "^5.1.6"
},
Expand All @@ -27,14 +27,15 @@
"@fortawesome/vue-fontawesome": "^3.0.3",
"@nuxt/image-edge": "1.0.0-rc.2-28246613.7d120ca",
"@pinia/nuxt": "^0.4.11",
"@vueuse/nuxt": "^10.3.0",
"@vueuse/core": "^10.3.0",
"@vueuse/integrations": "^10.3.0",
"eslint-config-custom": "workspace:*",
"floating-vue": "2.0.0-beta.24",
"nuxt-simple-sitemap": "^3.1.4",
"nuxt-umami": "^2.5.2",
"pinia": "^2.1.6",
"splitpanes": "^3.1.5",
"tailwind-config": "workspace:*",
"unstorage": "^1.8.0"
"universal-cookie": "^4.0.4"
}
}
5 changes: 4 additions & 1 deletion apps/app/pages/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ onMounted(async () => {
/>
<TaskModal :current-lesson="currentLesson" @next="redirectToNextLesson" />

<div class="mb-10 flex flex-wrap items-center gap-6 px-6 sm:px-8">
<div
v-if="currentCourse"
class="mb-10 flex flex-wrap items-center gap-6 px-6 sm:px-8"
>
<div
class="h-[160px] w-[160px] min-w-[160px] overflow-hidden rounded shadow-lg"
>
Expand Down
9 changes: 5 additions & 4 deletions apps/app/stores/clerk/session.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineStore } from "pinia";
import { useCookies } from "@vueuse/integrations/useCookies";

export const useSessionStore = defineStore("session", {
state: (): { token: string | null; cleared: boolean } => ({
Expand Down Expand Up @@ -26,10 +27,10 @@ export const useSessionStore = defineStore("session", {
await this.$clerk.setSession(clientSession);
},
async signOut() {
const clerkToken = useCookie("__session");
const userCookie = useCookie("m-user");
userCookie.value = null;
clerkToken.value = null;
const clerkToken = useCookies([]);
const userCookie = useCookies([]);
userCookie.remove("m-user");
clerkToken.remove("__session");
this.cleared = true;

await this.$clerk.signOut();
Expand Down
5 changes: 3 additions & 2 deletions apps/app/stores/clerk/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineStore } from "pinia";
import type { UpdateUserParams, SetProfileImageParams } from "@clerk/types";
import { useCookies } from "@vueuse/integrations/useCookies";

export type user = {
profileImageUrl: string;
Expand Down Expand Up @@ -38,8 +39,8 @@ export const useUserStore = defineStore("user", {
if (!userData) return;

this.user = userData;
const userCookie = useCookie("m-user");
userCookie.value = userData;
const userCookie = useCookies([]);
userCookie.set("rise-user", userData);
},
async updateUser() {
await this.$clerk.user.update<UpdateUserParams>({
Expand Down
2 changes: 1 addition & 1 deletion apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"@nuxtjs/fontaine": "^0.2.5",
"@types/node": "^20.4.6",
"nuxt": "^3.6.5",
"nuxt": "^3.7.3",
"nuxt-schema-org": "^2.2.0",
"nuxt-simple-robots": "^3.1.0",
"nuxt-simple-sitemap": "^3.1.4",
Expand Down
Loading

0 comments on commit ffcf206

Please sign in to comment.