Hi, I have problem with auth. When I try to login/signup using OTP, at the end session.secret is empty, but looks like a whole procces passed correctly. I have tried creating new API key (someone response from simillar post), but still don't work
Using Nextjs 14.2.8, node-appwrite 13
// app/signup/page.tsx
import { createAdminClient, getLoggedInUser } from "@/lib/server/appwrite"
import { cookies } from "next/headers"
import { redirect } from "next/navigation"
import { ID } from "node-appwrite"
export default async function SignupPage() {
const user = await getLoggedInUser()
if (user) redirect("/rooms")
return (
<>
<form action={sendEmail}>
<input type="email" name="email" placeholder="email@email.com" />
<button type="submit">Send Email</button>
</form>
<form action={login}>
<input type="text" name="code" placeholder="code" />
<button type="submit">Submit code</button>
</form>
</>
)
}
const sendEmail = async (formData: FormData) => {
'use server'
const email = formData.get('email') as string
const { account } = await createAdminClient()
const sessionToken = await account.createEmailToken(
ID.unique(),
email
)
cookies().set('user-id', sessionToken.userId, {
path: '/',
})
}
const login = async (formData: FormData) => {
'use server'
const code = formData.get('code') as string
const { account } = await createAdminClient()
const userID = cookies().get('user-id')?.value
const session = await account.createSession(
userID as string,
code
)
console.log(session, session.secret)
cookies().set('user-session', session.secret, {
path: '/',
sameSite: 'lax',
})
redirect('/rooms')
}```
// @/lib/server/appwrite
"use server"
import { cookies } from "next/headers"
import { Account, Client } from "node-appwrite"
export const createSessionClient = async () => {
const client = new Client()
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT as string)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT as string)
const session = cookies().get('user-session')
if (!session || !session.value) {
throw new Error('No session found')
}
client.setSession(session.value)
return {
get account() {
return new Account(client)
}
}
}
export const createAdminClient = async () => {
const client = new Client()
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT as string)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT as string)
.setKey(process.env.APPWRITE_API_KEY as string)
return {
get account() {
return new Account(client)
}
}
}
export const getLoggedInUser = async () => {
try {
const { account } = await createSessionClient()
return await account.get()
} catch (err) {
return null
}
}
{
'$id': '66e99b59ae204f8cea19',
'$createdAt': '2024-09-17T15:08:09.719+00:00',
'$updatedAt': '2024-09-17T15:08:09.719+00:00',
userId: '66e996ea0020587be57b',
expire: '2025-09-17T15:08:09.744+00:00',
provider: 'token',
providerUid: '',
providerAccessToken: '',
providerAccessTokenExpiry: '',
providerRefreshToken: '',
ip: '10.0.0.2',
osCode: 'LIN',
osName: 'GNU/Linux',
osVersion: '',
clientType: '',
clientCode: '',
clientName: '',
clientVersion: '',
clientEngine: '',
clientEngineVersion: '',
deviceName: 'desktop',
deviceBrand: '',
deviceModel: '',
countryCode: '--',
countryName: 'Unknown',
current: true,
factors: [ 'email' ],
secret: '',
mfaUpdatedAt: ''
}
Recommended threads
- Go 1.25 runtime
So I'm trying to use go 1.25 for my functions and I can only find go-1.23 as a function runtime. So I did some searching and found https://github.com/appwrite/a...
- [ENHANCEMENT] Use the custom Next.js dep...
Deployment adapters on Next.js are now stable! This means that we don't have to stick to the limitations of sniffing out build outputs and manually moving or mo...
- NextJS builds sudden runtime_timeout
My builds suddenly stopped working. Activating old prebuilt snapshots work, but redeploying that same code produces builds that throw runtime_timeout FRA region