File tree 5 files changed +36
-20
lines changed 5 files changed +36
-20
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ Use `sample.env` as a reference.
85
85
86
86
Go to the Appwrite console and get the following details from the project you created.
87
87
88
- - host
88
+ - endpoint
89
89
- project id
90
90
- database id
91
91
- collection id
Original file line number Diff line number Diff line change 1
- import { Models , Databases } from "appwrite" ;
2
1
import { IAccountOps , IBucketOps , ICollectionOps } from "./types" ;
3
2
import useAccount from "./useAccount" ;
4
3
import useBucket from "./useBucket" ;
@@ -11,9 +10,8 @@ export default function useAppwrite(): [
11
10
IBucketOps
12
11
] {
13
12
const client = useClient (
14
- process . env . NEXT_PUBLIC_APPWRITE_HOST ,
13
+ process . env . NEXT_PUBLIC_APPWRITE_ENDPOINT ,
15
14
process . env . NEXT_PUBLIC_APPWRITE_PROJECT ,
16
- process . env . NEXT_PUBLIC_APPWRITE_SSL === "true"
17
15
) ;
18
16
19
17
const account = useAccount ( client ) ;
Original file line number Diff line number Diff line change 1
1
import { Account , Client , Databases } from "appwrite" ;
2
2
import { useMemo } from "react" ;
3
3
4
+ function normalizeEndpoint (
5
+ endpoint : string ,
6
+ ) : string {
7
+ if ( endpoint . endsWith ( "/" ) ) {
8
+ return endpoint . substring ( 0 , endpoint . length - 1 ) ;
9
+ }
10
+ return endpoint ;
11
+ }
12
+
4
13
export default function useClient (
5
- host : string ,
6
- projectId : string ,
7
- ssl ?: boolean
14
+ endpoint : string ,
15
+ projectId : string
8
16
) : Client {
9
17
const client = useMemo ( ( ) => {
10
18
return new Client ( )
11
- . setEndpoint ( `http ${ ssl ? "s" : "" } :// ${ host } /v1` )
19
+ . setEndpoint ( normalizeEndpoint ( endpoint ) )
12
20
. setProject ( projectId ) ;
13
- } , [ host , projectId ] ) ;
21
+ } , [ endpoint , projectId ] ) ;
14
22
15
23
return client ;
16
24
}
Original file line number Diff line number Diff line change 1
- import Head from "next/head " ;
2
- import Image from "next/image " ;
3
- import MyHead from "../components/head " ;
4
- import styles from "../styles/Home.module.css " ;
1
+ import { useRouter } from "next/router " ;
2
+ import { useEffect } from "react " ;
3
+ import { Text } from "@chakra-ui/react " ;
4
+ import useAppwrite from "../hooks/appwrite/useAppwrite " ;
5
5
6
6
export default function Home ( ) {
7
- return (
8
- < div className = { styles . container } >
9
- < MyHead />
10
- </ div >
11
- ) ;
7
+ const [ account ] = useAppwrite ( ) ;
8
+ const router = useRouter ( ) ;
9
+
10
+ useEffect ( ( ) => {
11
+ if ( ! account . loading ) {
12
+ if ( account . user ) {
13
+ router . push ( "/feed" ) ;
14
+ } else {
15
+ router . push ( "/auth" ) ;
16
+ }
17
+ }
18
+ } , [ account . user , account . loading ] ) ;
19
+
20
+ if ( account . loading ) return < Text > Loading...</ Text > ;
21
+
22
+ return < > </ > ;
12
23
}
Original file line number Diff line number Diff line change 1
- NEXT_PUBLIC_APPWRITE_HOST = <host>
2
- NEXT_PUBLIC_APPWRITE_SSL = <true | false>
1
+ NEXT_PUBLIC_APPWRITE_ENDPOINT = <host>
3
2
NEXT_PUBLIC_APPWRITE_PROJECT = <project id>
4
3
NEXT_PUBLIC_APPWRITE_DATABASE = <database id>
5
4
NEXT_PUBLIC_APPWRITE_COLLECTION = <collection id>
You can’t perform that action at this time.
0 commit comments