From 016ef96190a2566fe7cd4f2f0e4507986cc6d47e Mon Sep 17 00:00:00 2001 From: Sahil Pahuja <19059570004@aryabhattacollege.ac.in> Date: Tue, 4 Jun 2024 12:58:48 +0530 Subject: [PATCH] feat: upgrade to Appwrite version 15 and updated website code --- package.json | 2 +- src/backend/auth.api.ts | 10 +++---- src/types/auth.d.ts | 3 +- yarn.lock | 63 +++++------------------------------------ 4 files changed, 15 insertions(+), 63 deletions(-) diff --git a/package.json b/package.json index 8a0e527..0658005 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@types/node": "20.4.10", "@types/react": "18.2.20", "@types/react-dom": "18.2.7", - "appwrite": "13.0.2", + "appwrite": "15.0.0", "autoprefixer": "10.4.14", "eslint": "8.47.0", "eslint-config-next": "13.4.13", diff --git a/src/backend/auth.api.ts b/src/backend/auth.api.ts index 5214655..7a3e45f 100644 --- a/src/backend/auth.api.ts +++ b/src/backend/auth.api.ts @@ -1,7 +1,7 @@ "use client"; import { account, db, ID, palettegramDB, usersCollection, Query } from "./appwrite.config"; import { generateAvatar } from "@/helper/avatarGenerator"; -import { Models } from "appwrite"; +import { Models, OAuthProvider } from "appwrite"; /** * @abstract Register the user into the database @@ -31,7 +31,7 @@ const register = async (userData: { throw new Error("User registration failed"); } - const session = await account.createEmailSession(userData.email, userData.password); + const session = await account.createEmailPasswordSession(userData.email, userData.password); if (!session) { throw new Error("Session failed"); @@ -145,7 +145,7 @@ const getUserByUserId = async (userId: string) => { const login = async (email: string, password: string) => { try { await account.deleteSessions(); - const response = await account.createEmailSession(email, password); + const response = await account.createEmailPasswordSession(email, password); if (!response) { throw new Error("Login failed"); @@ -203,7 +203,7 @@ const updatepassword = async (userData: any) => { if (password === "" || confirmpassword === "" || USER_ID === "" || SECRET === " ") { throw new Error("Request has failed"); } - const response = await account.updateRecovery(USER_ID, SECRET, password, confirmpassword); + const response = await account.updateRecovery(USER_ID, SECRET, password); return response; } catch (error: any) { console.log(error); @@ -287,7 +287,7 @@ const getSingleUser = async (email: string) => { const loginWithGithub = async () => { try { account.createOAuth2Session( - "github", + OAuthProvider.Github, `${process.env.NEXT_PUBLIC_BASE_URL}/feed`, `${process.env.NEXT_PUBLIC_BASE_URL}/login`, ["repo", "user"], diff --git a/src/types/auth.d.ts b/src/types/auth.d.ts index f707dda..8b4e243 100644 --- a/src/types/auth.d.ts +++ b/src/types/auth.d.ts @@ -27,9 +27,10 @@ export type userCollectionDB = { // }; export type userDetails = { - data: userCollectionDB | {}; + data: userCollectionDB | unknown; error: boolean; loading: boolean; + accountId?:string; }; export enum LoginOptions { diff --git a/yarn.lock b/yarn.lock index 290db19..148e9e5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1017,13 +1017,10 @@ anymatch@~3.1.2: normalize-path "^3.0.0" picomatch "^2.0.4" -appwrite@13.0.2: - version "13.0.2" - resolved "https://registry.npmjs.org/appwrite/-/appwrite-13.0.2.tgz" - integrity sha512-ISkUXO8pojDWGx5XqknCwwikgAQye4Ni4FL+Ns8Hg42rXeyehLlmvHGjFOmpS+odT6nsWYUaXzVjV4SZuDorog== - dependencies: - cross-fetch "3.1.5" - isomorphic-form-data "2.0.0" +appwrite@^15.0.0: + version "15.0.0" + resolved "https://registry.yarnpkg.com/appwrite/-/appwrite-15.0.0.tgz#73d609fe5c3a4bc9c87a651a8d7c21ef002e8c22" + integrity sha512-rzmo+87tizYLs3YnRLets+vMUF85S/OHkgiGgp0UKcKJj0U1RktAsuIecFqRROKfkqs0fKzggRAIs3RCoYQQwA== arg@^4.1.0: version "4.1.3" @@ -1400,7 +1397,7 @@ colorette@^2.0.20: resolved "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz" integrity sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w== -combined-stream@^1.0.6, combined-stream@^1.0.8: +combined-stream@^1.0.8: version "1.0.8" resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz" integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== @@ -1515,13 +1512,6 @@ crelt@^1.0.0: resolved "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz" integrity sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g== -cross-fetch@3.1.5: - version "3.1.5" - resolved "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz" - integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw== - dependencies: - node-fetch "2.6.7" - cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz" @@ -2282,15 +2272,6 @@ foreground-child@^3.1.0: cross-spawn "^7.0.0" signal-exit "^4.0.1" -form-data@^2.3.2: - version "2.5.1" - resolved "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz" - integrity sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA== - dependencies: - asynckit "^0.4.0" - combined-stream "^1.0.6" - mime-types "^2.1.12" - form-data@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz" @@ -2935,13 +2916,6 @@ isexe@^2.0.0: resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz" integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw== -isomorphic-form-data@2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/isomorphic-form-data/-/isomorphic-form-data-2.0.0.tgz" - integrity sha512-TYgVnXWeESVmQSg4GLVbalmQ+B4NPi/H4eWxqALKj63KsUrcu301YDjBqaOw3h+cbak7Na4Xyps3BiptHtxTfg== - dependencies: - form-data "^2.3.2" - iterator.prototype@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.2.tgz" @@ -3412,13 +3386,6 @@ node-appwrite@^11.1.0: axios "^1.4.0" form-data "^4.0.0" -node-fetch@2.6.7: - version "2.6.7" - resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz" - integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== - dependencies: - whatwg-url "^5.0.0" - node-releases@^2.0.14: version "2.0.14" resolved "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz" @@ -4455,6 +4422,7 @@ string-argv@0.3.2: integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q== "string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: + name string-width-cjs version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -4701,11 +4669,6 @@ toggle-selection@^1.0.6: resolved "https://registry.npmjs.org/toggle-selection/-/toggle-selection-1.0.6.tgz" integrity sha512-BiZS+C1OS8g/q2RRbJmy59xpyghNBqrr6k5L/uKBGRsTfxmu3ffiRnd8mlGPUVayg8pvfi5urfnu8TU7DVOkLQ== -tr46@~0.0.3: - version "0.0.3" - resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz" - integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== - ts-api-utils@^1.0.1: version "1.3.0" resolved "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz" @@ -4894,19 +4857,6 @@ watchpack@2.4.0: glob-to-regexp "^0.4.1" graceful-fs "^4.1.2" -webidl-conversions@^3.0.0: - version "3.0.1" - resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz" - integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ== - -whatwg-url@^5.0.0: - version "5.0.0" - resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz" - integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw== - dependencies: - tr46 "~0.0.3" - webidl-conversions "^3.0.0" - which-boxed-primitive@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz" @@ -4965,6 +4915,7 @@ which@^2.0.1: isexe "^2.0.0" "wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: + name wrap-ansi-cjs version "7.0.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==