
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@triplit/authjs-adapter
Advanced tools
Official Triplit adapter for Auth.js / NextAuth.js.
npm install @triplit/authjs-adapter
TriplitAdapter(server, token, options)
Add this adapter to your `pages/api/[...nextauth].js`` next-auth configuration object.
import NextAuth from "next-auth"
import { TriplitAdapter } from "@triplit/authjs-adapter"
import { schema } from "path/to/triplit/schema"
// For more information on each option (and a full list of options) go to
// https://authjs.dev/reference/core#authconfig
export default NextAuth({
// https://authjs.dev/reference/core/providers
providers: [...],
adapter: TriplitAdapter({
server: process.env.TRIPLIT_DB_URL,
token: process.env.TRIPLIT_SERVICE_TOKEN,
schema: schema
}),
// ...
})
Add the following schema to your Triplit database. The schema is described here.
In your triplit/schema.ts
file, add the following collections:
{
users: {
schema: S.Schema({
id: S.Id(),
name: S.String({ nullable: true, default: null }),
email: S.String({ nullable: true, default: null }),
emailVerified: S.Date({ nullable: true, default: null }),
image: S.String({ nullable: true, default: null }),
}),
},
accounts: {
schema: S.Schema({
id: S.Id(),
userId: S.String(),
type: S.String(),
provider: S.String(),
providerAccountId: S.String(),
refresh_token: S.String({ nullable: true, default: null }),
access_token: S.String({ nullable: true, default: null }),
expires_at: S.Number({ nullable: true, default: null }),
token_type: S.String({ nullable: true, default: null }),
scope: S.String({ nullable: true, default: null }),
id_token: S.String({ nullable: true, default: null }),
session_state: S.String({ nullable: true, default: null }),
}),
relationships: {
user: S.RelationById("users", "$1.userId")
}
},
sessions: {
schema: S.Schema({
id: S.Id(),
userId: S.String(),
expires: S.Date(),
sessionToken: S.String(),
}),
relationships: {
user: S.RelationById("users", "$1.userId")
}
},
verificationTokens: {
schema: S.Schema({
id: S.Id(),
identifier: S.String(),
token: S.String(),
expires: S.Date(),
}),
},
}
In local development, the Auth.js models should be available for use.
Configure Auth.js to use JWTs and assign them proper fields.
To sign the JWT, install the jose
package:
npm install jose
Using Auth.js callbacks, create a valid token and append it to the session
object.
import NextAuth from "next-auth"
import { TriplitAdapter } from "@auth/triplit-adapter"
import * as jwt from "jose"
// For more information on each option (and a full list of options) go to
// https://authjs.dev/reference/configuration/auth-options
export default NextAuth({
// https://authjs.dev/reference/core/providers
providers: [...],
adapter: TriplitAdapter({...}),
session: {
strategy: "jwt" as const,
},
jwt: {
secret: process.env.NEXTAUTH_SECRET,
encode: async ({ secret, token, maxAge }) => {
return await signToken(token, secret);
},
decode: async ({ secret, token }) => {
return await decodeToken(token!, secret)
},
},
callbacks: {
jwt: async ({ token, user }) => {
if (user) {
token["x-triplit-user-id"] = user.id
}
return token
},
async session({ session, token, user }) {
if (process.env.NEXTAUTH_SECRET) {
session.token = await signToken(token, process.env.NEXTAUTH_SECRET)
}
return session
},
async authorized({ request, auth }) {
return !!auth
},
},
// ...
});
async function signToken(token: any, secret: string) {
const alg = "HS256"
const secretKey = new TextEncoder().encode(secret)
const encodedToken = await new jwt.SignJWT(token)
.setIssuedAt()
.setExpirationTime("24h")
.setProtectedHeader({ alg })
.sign(secretKey)
return encodedToken
}
async function decodeToken(token: string, secret: string) {
const secretKey = new TextEncoder().encode(secret)
const decodedToken = await jwt.jwtVerify(token, secretKey, {
algorithms: ["HS256"],
})
return decodedToken.payload
}
Check out Triplit's example chat app for a full example.
FAQs
Unknown package
We found that @triplit/authjs-adapter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.